コード例 #1
0
ファイル: CRendering.java プロジェクト: estrom85/sample-codes
  private static Point getDeckPosition(CGraphics g_src, char type) {
    Point result = new Point();

    int offset;
    if (Character.toLowerCase(type) == 'd') offset = -3 * g_src.cardWidth() / 2;
    else offset = g_src.cardWidth() / 2;

    result.x = g_src.displayWidth() / 2 + offset;
    result.y = g_src.displayHeight() / 2 - g_src.cardHeight() / 2;

    return result;
  }
コード例 #2
0
ファイル: CRendering.java プロジェクト: estrom85/sample-codes
  /**
   * 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;
  }
コード例 #3
0
ファイル: CRendering.java プロジェクト: estrom85/sample-codes
 /**
  * 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);
 }
コード例 #4
0
ファイル: CRendering.java プロジェクト: estrom85/sample-codes
  /**
   * Displays card type when needed
   *
   * @param g - reference to graphic content
   * @param graphicSource - reference to class that contains informations about rendering
   * @param type - card type
   * @param mouseX - X position of mouse
   * @param mouseY - Y position of mouse
   * @param width - width of display
   * @param height - height of display
   */
  public static void displayCardType(Graphics g, CGraphics g_src, int type) {
    Image img = g_src.getType(type);
    Point deckPos = getDeckPosition(g_src, 'd');
    Point trashPos = getDeckPosition(g_src, 't');
    // get outline in between deck and trash
    int left = deckPos.x + g_src.cardWidth();
    int right = trashPos.x;
    int top = deckPos.y;
    int bottom = top + g_src.cardHeight();

    // adjust indicator box to square with size of 0.8 of space between decks
    int width = (int) ((double) (right - left) * 0.6);
    int offsetX = ((right - left) - width) / 2;
    int offsetY = ((bottom - top) - width) / 2;

    left += offsetX;
    right -= offsetX;
    top += offsetY;
    bottom -= offsetY;

    g.drawImage(img, left, top, right, bottom, 0, 0, img.getWidth(null), img.getHeight(null), null);
  }
コード例 #5
0
ファイル: CRendering.java プロジェクト: estrom85/sample-codes
  /**
   * 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);
  }