Beispiel #1
0
 /**
  * Renders other players hand
  *
  * @param g - reference to graphic content
  * @param graphicSource - reference to class that holds rendering information
  * @param player - reference to other player
  * @param numOfPlayers - total number of players around the table
  * @param width - width of display
  * @param height - height of display
  */
 public static void renderOtherPlayerHand(
     Graphics g, CGraphics g_src, CPlayer player, int numOfPlayers) {
   Point position = getPlayerPosition(player.index(), g_src, numOfPlayers);
   int numOfCards = player.getNumberOfCards();
   int width = g_src.cardWidth() * (int) (1 + 0.25 * (numOfCards - 1));
   int x = position.x + width / 2 - g_src.cardWidth();
   int y = position.y + g_src.cardHeight() / 2;
   Image img = g_src.getBackCard();
   for (int i = 0; i < numOfCards; i++) {
     g.drawImage(img, x - (int) (g_src.cardWidth() * 0.25 * i), y, null);
   }
   g.setColor(Color.BLACK);
   g.setFont(new Font("Arial", Font.BOLD, 15));
   String player_name = player.name() + " (" + player.getNumberOfCards() + ")";
   FontMetrics fontSize = g.getFontMetrics();
   int stringPos = position.x - fontSize.stringWidth(player_name) / 2;
   // g.drawString(player_name, position.x-width, y-15);
   g.drawString(player_name, stringPos, y - 15);
 }
Beispiel #2
0
  /**
   * Renders game table
   *
   * @param g - reference to graphic content
   * @param graphicSource - reference to class that contains rendering information
   * @param deck - refernce to deck
   * @param trash - reference to trash
   * @param width - width of display
   * @param height - height of display
   */
  public static void renderTable(
      String gameName,
      Graphics g,
      CGraphics g_src,
      CPacket deck,
      CPacket trash,
      int mouseX,
      int mouseY,
      boolean active,
      boolean activeTrash) {
    Graphics2D g2 = (Graphics2D) g;
    Point temp;
    Image img;

    int cardIndex = getCardIndex(null, g_src, mouseX, mouseY);

    // draw background
    g.drawImage(g_src.getBackground(), 0, 0, null);
    // draw name of game
    g.setColor(Color.WHITE);
    g.setFont(new Font("Arial", Font.BOLD | Font.ITALIC, 25));
    FontMetrics metrics = g.getFontMetrics();
    g.drawString(gameName, g_src.displayWidth() / 2 - metrics.stringWidth(gameName) / 2, 30);
    // draw table
    g.drawOval(15, 45, g_src.displayWidth() - 30, g_src.displayHeight() - 75);
    g.setColor(new Color(0, 0, 0, 50));
    g.fillOval(15, 45, g_src.displayWidth() - 30, g_src.displayHeight() - 75);

    // draw decks
    temp = getDeckPosition(g_src, 'd'); // save deck coords
    if (deck.isEmpty()) {
      // draws empty deck
      g.setColor(new Color(88, 88, 88, 125));
      g2.fill(g_src.getCardOutline(temp.x, temp.y));
    } else {
      // temporary stores back card
      img = g_src.getBackCard();
      // gets number of cards in deck
      int numDeckCards = deck.size();
      // if mouse is on the deck moves upmost card bit upward
      // Debug.println("cardIndex", Integer.toString(cardIndex));
      if (cardIndex == 100 && active)
        numDeckCards -= 1; // if mouseover num of cards rendered in deck is 1 less
      // draws deck
      for (int i = 0; i < numDeckCards; i++)
        g.drawImage(img, temp.x - (i - deck.size()) / 3, temp.y - (i - deck.size()) / 3, null);

      // if(g_src.getCardOutline(temp.x,temp.y).contains(mouseX, mouseY))
      if (cardIndex == 100 && active) {
        // draws mouseover card
        g.setColor(new Color(88, 88, 88, 120));
        g2.fill(g_src.getCardOutline(temp.x + 4, temp.y + 4));
        g.drawImage(img, temp.x - 2, temp.y - 1, null);
      }
    }
    // draws trash
    temp = getDeckPosition(g_src, 't');

    if (trash.isEmpty()) {
      g.setColor(new Color(88, 88, 88, 125));
      g2.fill(g_src.getCardOutline(temp.x + deck.size() / 3, temp.y + deck.size() / 3));
    } else {
      CCard topCard = trash.getTopCard();
      img = g_src.getFrontCard(topCard.getNumber(), topCard.getType());
      // gets number of cards in deck
      int numDeckCards = trash.size();
      // if mouse is on the deck moves upmost card bit upward
      // Debug.println("cardIndex", Integer.toString(cardIndex));
      if (cardIndex == 200 && activeTrash)
        numDeckCards -= 1; // if mouseover num of cards rendered in deck is 1 less
      // draws deck
      for (int i = 0; i < numDeckCards; i++)
        g.drawImage(img, temp.x - (i - trash.size()) / 3, temp.y - (i - deck.size()) / 3, null);
      if (cardIndex == 200 && activeTrash) {
        // draws mouseover card
        g.setColor(new Color(88, 88, 88, 120));
        g2.fill(g_src.getCardOutline(temp.x + 4, temp.y + 4));
        g.drawImage(img, temp.x - 2, temp.y - 1, null);
      }
    }
  }