Пример #1
0
  private void drawBalance(Graphics g)
        //  POST: Draws the balance of the current player
      {

    Font font; // Font used to draw balance
    String message; // Message for balance
    Color oldColor; // Sets for color
    int x1; // Upper-left x coordinate
    int y1; // Upper-left y coordinate
    int x2; // Bottom-right x coordinate
    int y2; // Bottom-right y coordinate
    int width; // Width of the dialogue box
    int height; // Height of the dialogue box
    int offset; // Offset so the dialogue box is positioned
    int balance; // Offset so the dialogue box is positioned
    User player; // User value for the player

    player = usersArray[0];

    balance = player.getBalance();
    oldColor = g.getColor();

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.81);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.86);
    width = x2 - x1;
    height = y2 - y1;
    message = "Balance:";
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.setColor(Color.WHITE);
    g.drawString(message, x1 + offset, y2);

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.865);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.915);

    width = x2 - x1;
    height = y2 - y1;
    message = "$" + Integer.toString(balance);
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.drawString(message, x1 + offset, y2);

    g.setColor(oldColor);
  }
Пример #2
0
  private void drawStoreMessage(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the store's dialogue box beneath the store image.
      {
    int x1; // Upper-left x coordinate.
    int y1; // Upper-left y coordinate.
    int x2; // Bottom-right x coordinate.
    int y2; // Bottom-right y coordinate.
    int width; // Width of dialogue box.
    int height; // Height of dialogue box.
    int numLines; // Number of lines in dialogue box.
    String message; // Message to be printed.

    x1 = ScaledPoint.scalerToX(storeMessagePos[0].getXScaler() + 0.01);
    y1 = ScaledPoint.scalerToY(storeMessagePos[0].getYScaler() + 0.01);
    x2 = ScaledPoint.scalerToX(storeMessagePos[1].getXScaler() - 0.01);
    y2 = ScaledPoint.scalerToY(storeMessagePos[1].getYScaler() - 0.01);
    width = x2 - x1;
    height = y2 - y1;

    Drawing.drawRoundedRect(g, storeMessagePos, Color.WHITE);

    switch (store) // change message based on value of store.
    {
      case 0:
        message = "If yer lookin' for a weapon, you've come to the right place.";
        break;

      case 1:
        message = "Welcome! You'll not find tougher steel elsewhere.";
        break;

      case 2:
        message = "Come! I guarantee you'll find something that catches your eye!";
        break;

      case 3:
        message = "Some say that many of my goods are trash... They're right.";
        break;

      default:
        message = "I don't know how you got here...";
    }

    numLines = 1;
    while (!(Drawing.drawWrappedString(g, message, numLines++, x1, y1, width, height)))
      ; // while we need more lines for the message
  }
Пример #3
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");
 }
Пример #4
0
  private void drawStoreName(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the store name along with a rounded border at the top of the window.
      {
    int rectWidth; // The width of the drawing area.
    int rectHeight; // The height of the drawing area.
    String storeName; // The name of the store.
    Font font; // The font to be used.

    rectWidth = nameLocation[1].getScaledX() - nameLocation[0].getScaledX();
    rectHeight = nameLocation[1].getScaledY() - nameLocation[0].getScaledY();

    switch (store) // set message based on store value.
    {
      case 0:
        storeName = "Raneac's Crucible";
        break;

      case 1:
        storeName = "The Iron Maiden";
        break;

      case 2:
        storeName = "The Grand Bazaar";
        break;

      default:
        storeName = "Miko's Wares";
    }

    font = Drawing.getFont(storeName, rectWidth, rectHeight, FONTNAME, FONTSTYLE);

    g.setFont(font);
    g.setColor(Color.WHITE);
    g.drawString(
        storeName, nameLocation[0].getScaledX(), (int) (nameLocation[1].getScaledY() * .98));
    Drawing.drawRoundedRect(g, nameLocation, Color.WHITE);
  }
Пример #5
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);
  }
Пример #6
0
  private void drawStoreBG(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the background associated with store.
      {
    switch (store) // draw background based on value of store.
    {
      case 0:
        Drawing.drawGradient(
            g, new Color(180, 80, 80), new Color(20, 0, 0), 0, 0, getWidth(), getHeight() / 2);
        Drawing.drawGradient(
            g,
            new Color(20, 0, 0),
            new Color(180, 80, 80),
            0,
            getHeight() / 2,
            getWidth(),
            getHeight() / 2 + 1);
        break;

      case 1:
        Drawing.drawGradient(
            g, new Color(80, 180, 80), new Color(0, 20, 0), 0, 0, getWidth(), getHeight());
        break;

      case 2:
        Drawing.drawGradient(
            g, new Color(230, 170, 50), new Color(60, 20, 0), 0, 0, getWidth(), getHeight());
        break;

      case 3:
        Drawing.drawGradient(
            g, new Color(120, 120, 120), new Color(20, 20, 20), 0, 0, getWidth(), getHeight());
        break;

      default:
        Drawing.drawGradient(
            g, new Color(80, 80, 180), new Color(0, 0, 20), 0, 0, getWidth(), getHeight());
    }
  }
Пример #7
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;
  }
Пример #8
0
  private void drawInventory(Graphics g)
        //  PRE:  g must be initialized.
        //  POST: Draws the inventory of the store if mode == 0, else draws the players inventory.
        //        If an item is selected, its border is highlighted white.
      {
    Graphics2D g2; // Graphics 2D object to allow for different brush stroke widths.
    Color start; // The start color for the inventory window gradient.
    Color end; // The end color for the inventory window gradient.
    int x1; // Upper-left x coordinate.
    int y1; // Upper-left y coordinate.
    int x2; // Bottom-right x coordinate.
    int y2; // Bottom-right y coordinate.
    int width; // Width of the inventory box.
    int height; // Height of the inventory box.
    int itemHeight; // The height of an item box.
    int itemY; // The y coordinate of the item.
    Item currentItem; // Item to store the current item

    g2 = (Graphics2D) g;
    start = new Color(120, 120, 220);
    end = new Color(50, 50, 150);

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

    while (height % ITEMSPERPAGE != 0) // ensure that the item boxes do not fall short of the window
    {
      height = ++y2 - y1;
    }

    itemHeight = height / ITEMSPERPAGE;

    Drawing.drawGradient(g2, start, end, x1, y1, width, height / 2);
    Drawing.drawGradient(g2, end, start, x1, y1 + height / 2, width, height / 2);

    g2.setColor(Color.BLACK);
    g2.setStroke(new BasicStroke(3));
    g2.drawRect(--x1, --y1, ++width, height);
    g2.setColor(Color.WHITE);

    switch (store) // Chooses the current store
    {
      case 0:
        connectItems(getUserItems("Weapon", orderToSort));
        break;
      case 1:
        connectItems(getUserItems("ArmorSmith", orderToSort));
        break;
      case 2:
        connectItems(getUserItems("Accessory", orderToSort));
        break;
      case 3:
        connectItems(getUserItems("General", orderToSort));
        break;
    }

    if (mode) // Sets mode to true for user inventory and displays
    {
      connectItems(getUserItems("Player", orderToSort));
    }

    int count = 0;
    // count = currentPage * ITEMSPERPAGE ;

    try // Try loading 10 items per page
    {

      currentItem = null;
      count = currentPage * ITEMSPERPAGE;
      for (int i = 0; i < ITEMSPERPAGE; i++) // draw each item into the window
      {
        if (i > itemsArray.length - 1) // Check if i excceds the array size
        {
          return;
        }
        itemY = y1 + (itemHeight) * i;

        currentItem = itemsArray[count];

        if (itemSelected == i) // if the item was selected, highlight it
        {
          g2.drawRect(x1, itemY, width, itemHeight);
        }

        drawItem(g2, i, currentItem);

        count++;
      }

    } catch (Exception e) // Catch generic exception and print it out
    {
      System.err.println(e.toString());
      System.err.println("Oh no, not like this...");
    }
  }