예제 #1
0
 private void showHelp(Graphics g)
       //  PRE:  g must be initialized.
       //  POST: Displays the help image to the screen.
     {
   JOptionPane.showMessageDialog(this, "Once you are satisfied, click anywhere to continue!");
   Drawing.drawImage(g, 0, 0, getWidth(), getHeight(), ".\\images\\help.jpg");
 }
예제 #2
0
  private void drawStoreImage(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the image associated with the store at the storeImage location.
        //        All images should be located in the \images\ directory.
      {
    String filePath; // the image file path
    int x; // x coordinate of upper-right corner of image.
    int y; // y coordinate of upper-right corner of image.
    int width; // width of image
    int height; // height of image

    x = storeImage[0].getScaledX();
    y = storeImage[0].getScaledY();
    width = storeImage[1].getScaledX() - storeImage[0].getScaledX();
    height = storeImage[1].getScaledY() - storeImage[0].getScaledY();

    switch (store) // initialize file path to image based on store
    {
      case 0:
        filePath = ".\\images\\weaponSmith.jpg";
        break;

      case 1:
        filePath = ".\\images\\armorSmith.jpg";
        break;

      case 2:
        filePath = ".\\images\\accessoryMerchant.jpg";
        break;

      case 3:
        filePath = ".\\images\\generalMerchant.png";
        break;

      default:
        filePath = ".\\images\\generalMerchant.png";
    }

    Drawing.drawImage(g, x, y, width, height, filePath);
  }
예제 #3
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;
  }