You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

public class Player {
String name;
Pile drawPile;
Pile discardPile;
public Player(String name, Pile drawPile) {
this.name = name;
this.drawPile = drawPile;
this.discardPile = new Pile();
}
public Pile getDrawPile() {
return drawPile;
}
public Pile getDiscardPile() {
return discardPile;
}
public void setDrawPile(Pile drawPile) {
this.drawPile = drawPile;
}
public void setDiscardPile(Pile discardPile) {
this.discardPile = discardPile;
}
public Card draw() throws NoMoreCardsException {
if (getDrawPile().isEmpty()) {
if (getDiscardPile().isEmpty()) {
throw new NoMoreCardsException();
}
discardPile.shuffle();
drawPile.takeDiscarded();
}
Card draw = drawPile.get(0);
drawPile.remove(0);
return draw;
}
public boolean broke() {
return drawPile.isEmpty() && discardPile.isEmpty();
}
public void addPot(Card[] draws) {
discardPile.addAll(draws);
}
public int cardsCount() {
return drawPile.count() + discardPile.count();
}
}