001 /*
002 * Created on 24.02.2005 Filename: Board.java
003 */
004 package jagafa.object;
005
006 import java.util.LinkedList;
007 import java.util.List;
008
009 /**
010 * The Board object holds alls the cards played including the information
011 * which Player played which Card (Is also a CardList)
012 */
013 public class Board extends CardList {
014 private List<Player> players_;
015
016 /**
017 * Constructor: Init the board and init playerList
018 */
019 public Board() {
020 super();
021 players_ = new LinkedList<Player>();
022
023 }
024
025 /**
026 * Copy Constructor: Init the board and init playerList
027 * @param b The board to copy
028 */
029 public Board(Board b) {
030 players_ = new LinkedList<Player>();
031 for (int i = 0; i < b.size(); i++) {
032 this.addCard(b.get(i).copy(), b.getPlayerOfPos(i));
033 }
034
035 }
036
037 /**
038 * Adds a Card to the Board
039 * @param c The card to add
040 * @param p The player which played the card
041 */
042 public void addCard(Card c, Player p) {
043 if (this.cardsPlayed() == 4) {
044 this.clearBoard();
045
046 }
047 super.add(c);
048 this.players_.add(p);
049
050 }
051
052 /**
053 * Clear the PlayerList
054 */
055 private void clearPlayers() {
056 players_ = new LinkedList<Player>();
057 }
058
059 /**
060 * Clear the Board
061 */
062 public void clearBoard() {
063 clearPlayers();
064 this.clear();
065 //System.out.println("----------------------------------------");
066 }
067
068 /**
069 * Get the number of cards on the board
070 * @return The number of Cards played
071 */
072 public int cardsPlayed() {
073 return super.size();
074 }
075
076 /**
077 * Get the Player who played the n-th card
078 * @return The Player who played the n-th card
079 * @param pos The position of the card
080 */
081 public Player getPlayerOfPos(int pos) {
082 if (players_.size() <= pos)
083 return null;
084 return this.players_.get(pos);
085 }
086
087 /**
088 * Get the color of the first card played
089 * @return The color of the first card on the Board
090 */
091 public int getFirstColor() {
092 return this.get(0).getColor();
093 }
094
095 /**
096 * Get the first card played
097 * @return The first card on the Board
098 */
099 public Card getFirstCard() {
100 return this.get(0);
101 }
102 }