예제 #1
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
  }
예제 #2
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);
  }