コード例 #1
10
ファイル: Component.java プロジェクト: BlaZedaroof/MineBlock
  public void render() {
    Graphics g = screen.getGraphics();
    // Drawing Things!
    sky.render(g);
    level.render(
        g,
        (int) sX,
        (int) sY,
        (pixel.width / Tile.tileSize) + 2,
        (pixel.height / Tile.tileSize) + 2);
    character.render(g);
    inventory.render(g);
    health.render(g);

    for (int i = 0; i < mob.toArray().length; i++) {
      mob.get(i).render(g);
    }
    g = getGraphics();

    g.drawImage(screen, 0, 0, size.width, size.height, 0, 0, pixel.width, pixel.height, null);

    g.dispose();
  }
コード例 #2
5
 public void addInventory(Inventory inv) {
   add(inv);
   inv.setBounds(x, y, 47, 42);
   if (last != count) {
     x += 50;
     last += 1;
   } else {
     x = 2;
     y += 50;
     last = 0;
   }
   setPreferredSize(new Dimension(82 * count, y + 30));
 }
コード例 #3
0
ファイル: Mart.java プロジェクト: Camtendo/jokemon
  // Handles all the buttons and crap
  public void actionPerformed(ActionEvent e) {
    for (int i = 0; i < pages.length; i++) {
      if (e.getSource() == pages[i]) {
        page = i + 1;
      }
    }
    if (e.getSource() == pockets[0]) {
      page = 1;
      changeSelection(Item.Pocket.ITEM);
    }
    if (e.getSource() == pockets[1]) {
      page = 1;
      changeSelection(Item.Pocket.MEDICINE);
    }
    if (e.getSource() == pockets[2]) {
      page = 1;
      changeSelection(Item.Pocket.POKEBALL);
    }
    if (e.getSource() == pockets[3]) {
      page = 1;
      changeSelection(Item.Pocket.TMHM);
    }
    if (e.getSource() == pockets[4]) {
      page = 1;
      changeSelection(Item.Pocket.BATTLE);
    }
    if (e.getSource() == closeButton) {
      closeWindow();
    }
    if (e.getSource() == information) {
      infoB = !infoB;
    }
    if (e.getSource() == buySellButton) {
      if (state == State.BUY) {
        state = State.SELL;
        buySellButton.setText("Selling");
        changeSelection(Item.Pocket.ITEM);
      } else {
        state = State.BUY;
        buySellButton.setText("Buying");
        changeSelection(Item.Pocket.ITEM);
      }
    }
    int num = (page - 1) * 10;
    for (int i = 0; i < display.length; i++) {
      if (e.getSource() == display[i] && !itemSelected) {
        itemSelected = true;
        selectedItemId = num + i;
      } else if (e.getSource() == display[i]) {
        totalAmount.setText("Enter Amount");
        itemSelected = false;
        buyButton.setEnabled(false);
        sellButton.setEnabled(false);
      }
    }
    if (e.getSource() == amountField && itemSelected) {
      try {
        amount = Integer.parseInt(amountField.getText());
        amount *= currentDisplay.get(selectedItemId).storeCost;
        if (amount < 0
            || (state == State.SELL
                    && amount / currentDisplay.get(selectedItemId).storeCost
                        > currentDisplay.get(selectedItemId).amount)
                && (state != State.SELL && !currentDisplay.get(selectedItemId).reUsable)) {
          totalAmount.setText("Error");
        } else if (state == State.SELL
            && Inventory.getItemInfo(currentDisplay.get(selectedItemId)).amount
                < amount / currentDisplay.get(selectedItemId).storeCost) {
          totalAmount.setText("Error");
        } else {
          if (state == State.BUY) totalAmount.setText("Total of $" + amount);
          else totalAmount.setText("Total of $" + amount / 2);
        }
        updateBuyButton();
        updateSellButton();
      } catch (Exception ee) {
        totalAmount.setText("Error");
      }
    }
    if (e.getSource() == buyButton) {
      Inventory.money -= amount;

      if (currentDisplay.get(selectedItemId).type != Item.Type.TM
          || currentDisplay.get(selectedItemId).type != Item.Type.HM)
        Inventory.addItem(
            new Item(
                currentDisplay.get(selectedItemId).type,
                amount / currentDisplay.get(selectedItemId).storeCost));
      else
        Inventory.addItem(
            new Item(
                currentDisplay.get(selectedItemId).type,
                amount / currentDisplay.get(selectedItemId).storeCost,
                currentDisplay.get(selectedItemId).mNo));

      itemSelected = false;
      totalAmount.setText("Enter Amount");
      buyButton.setEnabled(false);
    }
    if (e.getSource() == sellButton) {
      updateSellButton();

      if (!sellButton.isEnabled()) return;
      Inventory.money += amount / 2;
      amount = amount / currentDisplay.get(selectedItemId).storeCost;
      while (amount > 0) {
        Inventory.decrementItem(currentDisplay.get(selectedItemId), true);
        amount--;
      }
      totalAmount.setText("Enter Amount");
      sellButton.setEnabled(false);
      itemSelected = false;
      changeSelection(pocket);
    }

    updateGui();
  }