Exemplo n.º 1
0
  private void saveCurrent() {
    PrintWriter writer = null;

    try {
      writer = new PrintWriter("config.txt", "UTF-8");
      writer.println("PhoneNumbers:");

      for (String s : Main.getEmails()) {
        writer.println(s);
      }

      writer.println("Items:");

      for (Item s : Main.getItems()) {
        writer.println(s.getName() + "," + s.getWebsite());
      }

      results.setText("Current settings have been saved sucessfully.");
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }

    writer.close();
  }
Exemplo n.º 2
0
 private void paintItems(Graphics2D g2d) {
   for (Item item : c.getAllStuff()) {
     if (item != null) {
       if (item.flicker()) {
         g2d.drawImage(
             item.getImage(), item.getPosition().getX(), item.getPosition().getY(), this);
       }
     }
   }
 }
Exemplo n.º 3
0
  private void checkContainedItem(ResourceEntry entry, StructEntry container) {
    List<StructEntry> cont_list = ((AbstractStruct) container).getList();
    for (int i = 0; i < cont_list.size(); i++)
      if (cont_list.get(i) instanceof Item) {
        Item item = (Item) cont_list.get(i);

        ResourceRef itemRes = (ResourceRef) item.getAttribute("Item");
        if (!ResourceFactory.getInstance().resourceExists(itemRes.getResourceName())) {
          errorTable.addTableItem(
              new AreaTableLine(
                  entry,
                  container,
                  "Non existent item in container: " + itemRes.getResourceName()));
        }

        StructEntry wear = item.getAttribute("Wear");
        if (((DecNumber) wear).getValue() != 0) {
          errorTable.addTableItem(
              new AreaTableLine(entry, container, "Wear is: " + ((DecNumber) wear).getValue()));
        }

        for (int j = 1; j < 8 * ((Flag) item.getAttribute("Flags")).getSize(); j++)
          if (((Flag) item.getAttribute("Flags")).isFlagSet(j)) {
            errorTable.addTableItem(
                new AreaTableLine(
                    entry, container, "Item flag is: " + item.getAttribute("Flags").toString()));
            break;
          }
      }
  }
Exemplo n.º 4
0
  public void checkInput() {
    // SwingUtilities.invokeLater(new Runnable() {
    // public void run() {
    String text = inputText.getText();
    if (!text.equals("")) {
      appendToPane(text + "\n\n", Color.blue);
      inputText.setText("");
      if (text.startsWith("use ")) {
        ArrayList<Item> inventory = player.getInventory();
        String key = text.substring(4);
        boolean found = false;
        for (Item i : inventory) {
          if (i.getName().equalsIgnoreCase(key)) {
            found = true;
            i.use();
            break;
          }
        }
        if (!found) {
          appendToPane("Item does not exist in your iventory.\n\n", Color.black);
        } else {

        }
      }
      if (text.startsWith("inventory")) {
        ArrayList<Item> inventory = player.getInventory();
        if (inventory.size() > 0) {
          for (Item i : inventory) {
            appendToPane(i.getName() + "\n", Color.darkGray);
          }
        } else appendToPane("Your iventory is empty.\n\n", Color.black);
        appendToPane("#", Color.blue);
      } else {
        userInput = text;
      }
    }
    // }
    // });
  }
Exemplo n.º 5
0
  public void buyItemFromUser(User buyer, User seller, Item currentItem)
        // PRE:  buyer, seller, currentItem must be initialized
        // POST: Purchases item from the store and has stores it into inventory.
      {

    int buyer_balance; // The new balance of the buyer
    int seller_balance; // The new balance of the seller
    String str; // First query
    String str2; // Second query
    String str3; // Third query

    buyer_balance = buyer.getBalance() - currentItem.getPrice();
    seller_balance = seller.getBalance() + currentItem.getPrice();

    if (buyer_balance > 0) // If the buyer wont go negative
    {
      str =
          String.format(
              "Update users set balance = (%d) where user_name = '%s'",
              buyer_balance, buyer.getUserName());

      str2 =
          String.format(
              "Update users set balance = (%d) where user_name = '%s'",
              seller_balance, seller.getUserName());

      str3 =
          String.format(
              "Update items set owner_id = (%d) where item_name = '%s'",
              buyer.getUserId(), currentItem.getItemName());

      updateTables(str, str2, str3);

    } else {
      // Prompt the user with an error
      JOptionPane.showMessageDialog(
          null, "You will go bankrupt if you try buying that, try selling some items.");
    }
  }
Exemplo n.º 6
0
  private void displayInformation() {
    results.setText("-Cell Phones-\n");
    if (Main.getEmails().isEmpty()) {
      results.append("\nNo Numbers");
    } else {
      ArrayList<String> emails = Main.getEmails();
      int index = 0;

      for (String s : emails) {
        index++;
        results.append("\n(" + index + ")   " + s);
      }
    }

    results.append("\n\n-Current Items-");
    if (Main.getItems().isEmpty()) {
      results.append("\n\nNo Items");
    } else {
      ArrayList<Item> items = Main.getItems();
      int index = 0;

      for (Item i : items) {
        String s = i.getWebsite().substring(46, i.getWebsite().length());

        index++;

        for (int j = 0; j < s.length(); j++) {
          if (s.substring(j, j + 1).equals("&")) {
            s = s.substring(0, j);
          }
        }

        results.append("\n\n(" + index + ")\nName: \t" + i.getName() + "\nItem: \t" + s);
      }
      results.append("\n\n");
    }
  }
  private void showPopup() {
    if (isEnabled()) {
      if (popup.isVisible()) {
        popup.setVisible(false);
      } else {
        Component[] components = popup.getComponents();
        if (components != null) {
          for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof Item) ((Item) components[i]).removeActionListener(this);
            else if (components[i] instanceof MenuItem) {
              Component[] subcomponents = ((MenuItem) components[i]).getComponents();
              for (int j = 0; j < components.length; j++) {
                if (components[j] instanceof Item)
                  ((Item) components[j]).removeActionListener(this);
              }
            }
          }
        }
        popup.removeAll();
        if (values == null) return;
        for (int i = 0; i < values.length; i++) {
          JMenuItem item = null;
          if (values[i] instanceof ListDescriptor) {
            ListDescriptor descriptor = (ListDescriptor) values[i];
            Icon icon = descriptor.getIcon();
            item = new Item(values[i].toString(), icon, i);
            item.addActionListener(this);
          } else if (values[i] instanceof AddElement) {
            AddElement element = (AddElement) values[i];
            Icon icon = element.getIcon();

            Object[] choiceValues = element.getChoiceValues();
            if (choiceValues != null) {
              item = new MenuItem(element.toString(), icon, i);
              for (int j = 0; j < choiceValues.length; j++) {
                if (choiceValues[j] == null) {
                  ((JMenu) item).addSeparator();
                  continue;
                }
                Item subItem = new Item(choiceValues[j].toString(), j);
                ((JMenu) item).add(subItem);
                subItem.setParentIndex(i);
                subItem.addActionListener(this);
              }
            } else {
              item = new Item(element.toString(), icon, i);
              item.addActionListener(this);
            }
            item.setVisible(element.isVisible());
            item.setEnabled(element.isEnabled());
          } else {
            if (values[i] != null) {
              item = new Item(values[i].toString(), i);
              item.addActionListener(this);
            }
          }
          if (item != null) {
            popup.add(item);
          } else popup.addSeparator();
        }
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                AwtUtil.showPopupPanel(PopupMenuButton.this, popup);
              }
            });
      }
    }
  }
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jbSaveLayer) {
      try {
        FileOutputStream fout = new FileOutputStream(jtfCengMing.getText() + ".wyf");
        ObjectOutputStream oout = new ObjectOutputStream(fout);
        oout.writeObject(itemArray);
        oout.close();
        fout.close();
      } catch (Exception ea) {
        ea.printStackTrace();
      }
    } else if (e.getSource() == jbLoadLayer) {
      try {
        FileInputStream fin = new FileInputStream(jtfCengMing.getText() + ".wyf");
        ObjectInputStream oin = new ObjectInputStream(fin);
        itemArray = (Item[][]) oin.readObject();

        oin.close();
        fin.close();
        this.flush();
      } catch (Exception ea) {
        ea.printStackTrace();
      }
      lvp.repaint();
    } else if (e.getSource() == jbLoadAll) { // 全部铺上当前选中

      for (int row = 0; row < 40; row++) {
        for (int col = 0; col < 60; col++) {
          Item item = ((Item) (jl.getSelectedValue())).clone();
          itemArray[row][col] = item;
          if (item != null) {
            item.setPosition(col, row);
          }
        }
      }

      lvp.repaint();
    } else if (e.getSource() == jbCreate) { // 生成源代码

      try {
        FileOutputStream fout = null;
        DataOutputStream dout = null;
        fout = new FileOutputStream("maps.so");
        dout = new DataOutputStream(fout);
        int totalBlocks = 0;

        for (int i = 0; i < 40; i++) {
          for (int j = 0; j < 60; j++) {
            Item item = itemArray[i][j];
            if (item != null) {
              totalBlocks++;
            }
          }
        }
        System.out.println("totalBlocks=" + totalBlocks);

        // 写入不空块的数量
        dout.writeInt(totalBlocks);

        for (int i = 0; i < 40; i++) {
          for (int j = 0; j < 60; j++) {
            Item item = itemArray[i][j];
            if (item != null) {
              int w = item.w; // 元素的图片宽度
              int h = item.h; // 元素的图片高度
              int col = item.col; // 元素的地图列
              int row = item.row; // 元素的地图行
              int pCol = item.pCol; // 元素的占位列
              int pRow = item.pRow; // 元素的占位行
              String leiMing = item.leiMing; // 类名

              int[][] notIn = item.notIn; // 不可通过
              int[][] keYu = item.keYu; // 可遇矩阵

              // 计算图片下标
              int outBitmapInxex = 0;
              if (leiMing.equals("Grass")) {
                outBitmapInxex = 0;
              } else if (leiMing.equals("XiaoHua1")) {
                outBitmapInxex = 1;
              } else if (leiMing.equals("MuZhuang")) {
                outBitmapInxex = 2;
              } else if (leiMing.equals("XiaoHua2")) {
                outBitmapInxex = 3;
              } else if (leiMing.equals("Road")) {
                outBitmapInxex = 4;
              } else if (leiMing.equals("Jing")) {
                outBitmapInxex = 5;
              }

              dout.writeByte(outBitmapInxex); // 记录图片下标
              dout.writeByte(0); // 记录可遇标志 0-不可遇 底层都不可遇
              dout.writeByte(w); // 图片宽度
              dout.writeByte(h); // 图片高度
              dout.writeByte(col); // 总列数
              dout.writeByte(row); // 总行数
              dout.writeByte(pCol); // 占位列
              dout.writeByte(pRow); // 占位行

              int bktgCount = notIn.length; // 不可通过点的数量
              dout.writeByte(bktgCount); // 写入不可通过点的数量

              for (int k = 0; k < bktgCount; k++) {
                dout.writeByte(notIn[k][0]);
                dout.writeByte(notIn[k][1]);
              }
            }
          }
        }

        dout.close();
        fout.close();

      } catch (Exception ea) {
        ea.printStackTrace();
      }
    }
  }
Exemplo n.º 9
0
  @Override
  public void keyPressed(KeyEvent e) {
    int option; // The option the user selected.
    User buyer; // User object for buyer
    User seller; // User object for seller
    Item selected_item; // Item object for selected item

    if (help) // if in help mode
    {
      return;
    }

    switch (e.getKeyCode()) // handle event associated with key
    {
      case KeyEvent.VK_F1: // if f1 was pressed
        switchStore(0);
        break;

      case KeyEvent.VK_F2: // if f2 was pressed
        switchStore(1);
        break;

      case KeyEvent.VK_F3: // if f3 was pressed
        switchStore(2);
        break;

      case KeyEvent.VK_F4: // if f4 was pressed
        switchStore(3);
        break;

      case KeyEvent.VK_D: // if d or right was pressed
      case KeyEvent.VK_RIGHT:
        if (currentPage != totalPages - 1) // if we are not on the last page
        {
          currentPage++;
          itemSelected = -1;
        }
        break;

      case KeyEvent.VK_A: // if a or left was pressed
      case KeyEvent.VK_LEFT:
        if (currentPage != 0) // if we are not on the first page
        {
          currentPage--;
          itemSelected = -1;
        }
        break;

      case KeyEvent.VK_W: // if w or up was pressed
      case KeyEvent.VK_UP:
        if (itemSelected == -1) // if no items currently selected
        {
          itemSelected = 0;
        } else // if an item was selected
        {
          itemSelected--;
          if (itemSelected < 0) // loop if at beginning of list
          {
            itemSelected = ITEMSPERPAGE - 1;
          }
        }

        break;

      case KeyEvent.VK_S: // if s or down was pressed
      case KeyEvent.VK_DOWN:
        itemSelected++;

        if (itemSelected >= ITEMSPERPAGE) // if at end of list, loop around
        {
          itemSelected = 0;
        }

        break;

      case KeyEvent.VK_ENTER: // if enter was pressed
        if (itemSelected == -1) // if no item was selected
        {
          break;
        }

        selected_item = itemsArray[itemSelected];

        option =
            JOptionPane.showConfirmDialog(
                this, ((!mode) ? "Buy " : "Sell ") + "for " + "$" + selected_item.getPrice() + "?");

        if (option == 0 && mode) // if they choose to buy
        {
          buyer = usersArray[0];
          switch (store) // change message based on value of store.
          {
            case 0:
              seller = usersArray[2];
              break;

            case 1:
              seller = usersArray[1];
              break;

            case 2:
              seller = usersArray[3];
              break;

            case 3:
              seller = usersArray[4];
              break;

            default:
              seller = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);

        } else if (option == 0 && mode) // if they choose to sell
        {
          seller = usersArray[0];

          switch (store) // change message based on value of store.
          {
            case 0:
              buyer = usersArray[2];
              break;

            case 1:
              buyer = usersArray[1];
              break;

            case 2:
              buyer = usersArray[3];
              break;

            case 3:
              buyer = usersArray[4];
              break;

            default:
              buyer = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);
        }

        itemSelected = -1;
        break;

      default:
        return;
    }

    repaint();
  }
Exemplo n.º 10
0
  @Override
  public void mousePressed(MouseEvent e) {
    CustomButton buttonPressed; // Button that was pressed.
    String buttonName; // The name of the button.
    int option; // Option chosen by user.
    User buyer; // User object for buyer
    User seller; // User object for seller
    Item selected_item; // Item object for selected item

    if (help) // if in help mode
    {
      help = false;
      repaint();
      return;
    }

    wasItemSelected(e.getX(), e.getY());
    buttonPressed = CustomButton.wasPressed(e.getX(), e.getY());

    if (buttonPressed == null) // if no button was pressed
    {
      return;
    }

    buttonName = buttonPressed.getName();
    playAudio(-1);

    switch (buttonName) // handle event associated with button name
    {
      case "rightTab":
        currentPage++;
        itemSelected = -1;
        break;

      case "leftTab":
        currentPage--;
        itemSelected = -1;
        break;

      case "buyTab":
        mode = false;
        break;

      case "sellTab":
        mode = true;
        break;

      case "button":
        selected_item = itemsArray[itemSelected];

        option =
            JOptionPane.showConfirmDialog(
                this, ((!mode) ? "Buy " : "Sell ") + "for " + "$" + selected_item.getPrice() + "?");

        if (option == 0 && (!mode)) // if they choose to buy
        {
          buyer = usersArray[0];
          switch (store) // change message based on value of store.
          {
            case 0:
              seller = usersArray[2];
              break;

            case 1:
              seller = usersArray[1];
              break;

            case 2:
              seller = usersArray[3];
              break;

            case 3:
              seller = usersArray[4];
              break;

            default:
              seller = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);

        } else if (option == 0 && mode) // if they choose to sell
        {
          seller = usersArray[0];

          switch (store) // change message based on value of store.
          {
            case 0:
              buyer = usersArray[2];
              break;

            case 1:
              buyer = usersArray[1];
              break;

            case 2:
              buyer = usersArray[3];
              break;

            case 3:
              buyer = usersArray[4];
              break;

            default:
              buyer = usersArray[1];
          }

          buyItemFromUser(buyer, seller, selected_item);
        }

        itemSelected = -1;
        break;

      case "nextStore":
        if (++store == NUMSTORES) // if we're on the last store, loop around
        {
          store = 0;
        }

        switchStore(store);
        break;

      case "sort":
        // something
        orderToSort =
            JOptionPane.showOptionDialog(
                this,
                "Sort by:",
                "Sort",
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                SORTOPTIONS,
                null);

        break;

      case "help":
        help = true;
        break;

      default:
    }

    repaint();
  }
Exemplo n.º 11
0
  private void drawItem(Graphics g, int item, Item currentItem) {
    Font font; // The font to be used.
    int x1; // The first x coordinate of drawing area.
    int y1; // The first y coordinate of drawing area.
    int x2; // The second x coordinate of drawing area.
    int y2; // The second y coordinate of drawing area.
    int width; // Width of drawing area.
    int height; // Height of drawing area.

    int iconX; // x coordinate of the icon.
    int iconY; // y coordinate of the icon.
    int iconLength; // Length of the icon.

    int itemNameX; // The x coordinate of the item name.
    int itemNameLength; // The length of the item name.

    int itemPriceX; // The x coordinate of the item price.
    int itemPriceWidth; // The width of the item price.

    x1 = itemPositions[item][0].getScaledX();
    x2 = itemPositions[item][1].getScaledX();
    y1 = itemPositions[item][0].getScaledY();
    y2 = itemPositions[item][1].getScaledY();
    width = x2 - x1;
    height = y2 - y1;

    iconX = x1 + (int) (width * .01);
    iconY = y1 + (int) (height * .1);
    iconLength = (int) (height * .8);

    Drawing.drawImage(g, iconX, iconY, iconLength, iconLength, currentItem.getItemPath());

    itemNameX = iconX + (int) (iconLength * 1.5);
    itemNameLength = (int) (width * 0.6);

    font =
        Drawing.getFont(
            currentItem.getItemName(),
            itemNameLength,
            (int) (iconLength * 0.8),
            FONTNAME,
            FONTSTYLE);

    g.setFont(font);
    g.setColor(Color.WHITE);
    g.drawString(currentItem.getItemName(), itemNameX, iconY + (int) (iconLength * 0.9));

    itemPriceX = x1 + (int) (width * 0.8);
    itemPriceWidth = (int) (width * 0.15);

    font =
        Drawing.getFont(
            Integer.toString(currentItem.getPrice()),
            itemPriceWidth,
            iconLength,
            FONTNAME,
            FONTSTYLE);
    g.setFont(font);
    g.setColor(Color.WHITE);
    g.drawString(
        Integer.toString(currentItem.getPrice()), itemPriceX, iconY + (int) (iconLength * .9));

    return;
  }