Package pdp.scrabble.ihm

Source Code of pdp.scrabble.ihm.PlayersRack

package pdp.scrabble.ihm;

import java.awt.Dimension;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Iterator;
import pdp.scrabble.game.GameEnvironment;
import pdp.scrabble.game.Letter;
import pdp.scrabble.game.Player;
import pdp.scrabble.game.Rack;
import static pdp.scrabble.game.BoardCase.CASE_SIZE;

/** Represents others player rack.
*/
public class PlayersRack extends JPanel {
    private static final long serialVersionUID = 1L;

    private static final Color RACK_COLOR = new Color(204, 153, 51);

    private static final int RACK_HEIGHT = CASE_SIZE + 24;

    /** Game reference. */
    private GameEnvironment game = null;

    /** Create a new players rack panel.
     * @param game game reference.
     */
    public PlayersRack(GameEnvironment game) {
  super();
  this.game = game;
  int maxY = RACK_HEIGHT * this.game.getPlayerNumber();
  this.setPreferredSize(new Dimension(330, maxY));
    }

    @Override
    public void paintComponent(Graphics g) {
  Iterator<Player> players = this.game.getPlayerList().iterator();
  int x = 28, y = 0;

  while (players.hasNext()) {
      Player player = players.next();
      if (player != null) {

    // Render player rack
    g.setColor(RACK_COLOR);
    g.fill3DRect(x + 16, 12 + y, 306, 45, true);
    g.fill3DRect(x + 9, 12 + y, 7, 55, true);
    g.fill3DRect(x + 322, 12 + y, 7, 55, true);
    g.fill3DRect(x + 5, 57 + y, 329, 11, true);

    // For each rack letter
    for (int i = 0; i < Rack.MAX_RACK_LETTERS; i++) {
        Letter letter = player.getRack().getLetter(i);
        int x1 = x + 16 + i * (CASE_SIZE + 4);
        int y1 = 16 + y;

        // Draw empty case
        g.setColor(Color.BLACK);
        g.drawRect(x1, y1, CASE_SIZE, CASE_SIZE);

        // Draw occupied case
        if (letter != null) {
      letter.render(g, x1, y1);
        }
    }

    y += RACK_HEIGHT;
      }
  }
    }
}
TOP

Related Classes of pdp.scrabble.ihm.PlayersRack

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.