001 /*
002 * Created on 16.03.2005
003 *
004 * Filename: GoneCardStack.java
005 */
006 package jagafa.object;
007
008 import jagafa.stats.CardTool;
009
010 import java.util.LinkedList;
011 import java.util.List;
012
013 /**
014 * GoneCardHeap is a CardList which holds all Cards that have been played during
015 * a Game, including the winners of every turn
016 *
017 */
018 public class GoneCardHeap extends CardList {
019 private List<Board> boardList_;
020
021 private List<Player> winnerList_;
022
023 /**
024 * Constructor: Init the winner and board Lists
025 */
026 public GoneCardHeap() {
027 super();
028 this.winnerList_ = new LinkedList<Player>();
029 this.boardList_ = new LinkedList<Board>();
030 }
031
032 /**
033 * Adds the turn to the GoneCardHeap
034 * @param b The turns Board object
035 * @param winner The turns winner
036 */
037 public void addTurn(Board b, Player winner) {
038 this.winnerList_.add(winner);
039 Board b2 = new Board(b);
040 super.addAll(b2);
041 this.boardList_.add(b2);
042 }
043
044 /**
045 * @return True, if the card is in the GoneCardHeap
046 */
047 public boolean isGone(Card c) {
048 return super.contains(c);
049 }
050
051 /**
052 * @return a CardList with all the Cards of the color given in the GoneCardHeap
053 * @param color The color number
054 */
055 public CardList getGoneOfColor(int color) {
056 CardList list = CardTool.getAllOfColor(this, color);
057 return list;
058 }
059
060 /**
061 * @return The board played in Turn number i
062 * @param turnNr The turn number
063 */
064 public Board getBoard(int turnNr) {
065 return this.boardList_.get(turnNr);
066 }
067
068 /**
069 * @return The winner of the turn specified
070 * @param turnNr The turn number
071 */
072 public Player getWinner(int turnNr) {
073 return this.winnerList_.get(turnNr);
074 }
075
076 /**
077 * @return The number of turns stored in the GoneCardHeap
078 */
079 public int turns() {
080 return this.boardList_.size();
081 }
082
083 /**
084 * @return True, if the Player player has played "color" in the Board given
085 * @param player The relevant player
086 * @param board The relevant board
087 */
088 public boolean hasPlayedColorIn(Player player, Board board) {
089 int firstColor = board.getFirstColor();
090
091 Card playerC = getPlayedCard(player, board);
092 if (playerC.getColor() == firstColor) {
093 return true;
094 } else {
095 return false;
096 }
097
098
099 }
100
101 /**
102 * Get the card a specific Player played on a specific Board
103 * @return The Card Player p has played in the Board given
104 * @param player The relevant player
105 * @param b The relevant board
106 */
107 public Card getPlayedCard(Player player, Board b) {
108 int firstColor = b.get(0).getColor();
109
110 for (int i = 0; i < b.size(); i++) {
111 if (b.getPlayerOfPos(i).equals(player)) {
112
113 Card playerC = b.get(i);
114 return playerC;
115 }
116 }
117
118 return null;
119 }
120
121 }