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.
55 lines
1017 B
55 lines
1017 B
/**
|
|
* The type Player.
|
|
*/
|
|
public class Player {
|
|
/**
|
|
* The Name.
|
|
*/
|
|
final String name;
|
|
/**
|
|
* The Draw pile.
|
|
*/
|
|
final Pile drawPile;
|
|
/**
|
|
* The Discard pile.
|
|
*/
|
|
final Pile discardPile;
|
|
|
|
/**
|
|
* Instantiates a new Player.
|
|
*
|
|
* @param name the name
|
|
* @param drawPile the draw pile
|
|
*/
|
|
public Player(String name, Pile drawPile) {
|
|
this.name = name;
|
|
this.drawPile = drawPile;
|
|
this.discardPile = new Pile();
|
|
}
|
|
|
|
/**
|
|
* Draw card.
|
|
*
|
|
* @return the card
|
|
*/
|
|
public Card draw() {
|
|
if (drawPile.isEmpty()) {
|
|
discardPile.shuffle();
|
|
drawPile.addAll(discardPile);
|
|
discardPile.clear();
|
|
}
|
|
Card draw = drawPile.get(0);
|
|
drawPile.remove(0);
|
|
return draw;
|
|
}
|
|
|
|
/**
|
|
* Cards count int.
|
|
*
|
|
* @return the int
|
|
*/
|
|
public int cardsCount() {
|
|
return drawPile.size() + discardPile.size();
|
|
}
|
|
}
|