Esempio n. 1
0
  /**
   * Based on rendering information returns card index selected
   *
   * @param player - refernce to player
   * @param event - reference to mouse event handler
   * @return index of card depending on mouse position
   */
  public static int getCardIndex(CPlayer player, CGraphics g_src, int mouseX, int mouseY) {

    Point mouse = new Point(mouseX, mouseY);
    Point pos;

    pos = getDeckPosition(g_src, 'd');

    if (g_src.getCardOutline(pos.x, pos.y).contains(mouse.x, mouse.y)) return 100;

    pos = getDeckPosition(g_src, 't');
    if (g_src.getCardOutline(pos.x, pos.y).contains(mouse.x, mouse.y)) return 200;

    if (player == null) return -1;

    /*

    int j=((T_CHumanPlayer)mPlayers[0]).selected();

    if(j>-1)
        if(T_CGraphics.getCardOutline(playerCardsCoords[j][0], playerCardsCoords[j][1]-25)
                .contains(x, y))
            return j;
    */
    int offset = (int) ((0.65 * g_src.displayWidth()) / (player.getNumberOfCards() - 1));
    for (int i = player.getNumberOfCards() - 1; i > -1; i--) {
      int x = (int) ((0.35 / 2) * g_src.displayWidth() - g_src.cardWidth() / 2 + offset * i);
      int y = (int) (0.95 * g_src.displayHeight() - g_src.cardHeight());
      if (g_src.getCardOutline(x, y).contains(mouse.x, mouse.y)) return i;
    }

    return -1;
  }
Esempio n. 2
0
  /**
   * Renders player hand
   *
   * @param g - refernce to class Graphics that takes care of displaying play field
   * @param graphicSource - refernce to class that holds rendering information
   * @param player - reference to human player
   * @param mouseX - Xposition of mouse
   * @param mouseY - Yposition of mouse
   * @param width - width of display
   * @param height - height of display
   */
  public static void renderPlayerHand(
      Graphics g, CGraphics g_src, CPlayer player, int mouseX, int mouseY, boolean active) {

    int numOfCards = player.getNumberOfCards();
    // sets space between each card. Distance between first and last card has to be maximum 0.65 of
    // display width
    int offset = (int) ((0.65 * g_src.displayWidth()) / (numOfCards - 1));
    // position indicators - stores info about position of card
    int y;
    int x;
    // temporary stores image of card before rendering
    Image temp;
    // index of card on which is mouse on

    int i = -1;
    if (active) i = getCardIndex(player, g_src, mouseX, mouseY);
    // position of card on which mouse is on
    int x2 = 0;
    int y2 = 0;

    // displays cards on field
    for (int j = 0; j < numOfCards; j++) {
      // gets card position
      x = (int) ((0.35 / 2) * g_src.displayWidth() - g_src.cardWidth() / 2 + offset * j);
      y = (int) (0.95 * g_src.displayHeight() - g_src.cardHeight());
      /*
      if(g_src.getCardOutline(x, y).contains(mouseX, mouseY)){
          x2=x;
          y2=y;
          i=j;
        //  continue;
      }
      */

      // skips rendering of card, which has mouse on and stores card position
      if (i == j) {
        x2 = x;
        y2 = y;
        continue;
      }

      // renders card
      temp = g_src.getFrontCard(player.getCard(j).getNumber(), player.getCard(j).getType());
      g.drawImage(temp, x, y, null);
    }

    // renders card, which has mouse on it
    if (i > -1 && i < 50) {
      // sets and renders shadow
      g.setColor(new Color(88, 88, 88, 120));
      ((Graphics2D) g).fill(g_src.getCardOutline(x2 + 4, y2 + 4));
      // renders card which is position bit above all others cards
      temp = g_src.getFrontCard(player.getCard(i).getNumber(), player.getCard(i).getType());
      g.drawImage(temp, x2 - 2, y2 - 2, null);
    }
    // prints out information about player hand
    x = (int) ((0.35 / 2) * g_src.displayWidth() - g_src.cardWidth() / 2);
    y = (int) (0.95 * g_src.displayHeight() - g_src.cardHeight()) - 15;
    String karta;
    switch (player.getNumberOfCards()) {
      case 1:
        karta = "karta";
        break;
      case 2:
      case 3:
      case 4:
        karta = "karty";
        break;
      default:
        karta = "kariet";
        break;
    }
    g.setColor(Color.BLACK);
    g.setFont(new Font("Arial", Font.BOLD, 15));
    g.drawString(player.name() + ": " + player.getNumberOfCards() + " " + karta, x, y);
  }
Esempio n. 3
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);
      }
    }
  }