mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-31 15:07:42 -08:00
Update Player object and initialize Players
This commit is contained in:
@@ -2,16 +2,30 @@ import java.util.LinkedList;
|
||||
|
||||
public class Player {
|
||||
|
||||
// TODO add 'playerNumber' property. e.g. playerNumber = 1 means "this is Player 1"
|
||||
private int playerNumber; // e.g. playerNumber = 1 means "this is Player 1"
|
||||
private int currentBet;
|
||||
private int total;
|
||||
private LinkedList<Card> hand;
|
||||
// TODO we'll need to decide how to deal with a split hand or doubled down bet.
|
||||
|
||||
public Player() {
|
||||
// TODO initilize 'total' to zero and 'hand' to an empty List
|
||||
/**
|
||||
* Represents a player in the game with cards, bets, total and a playerNumber.
|
||||
*/
|
||||
public Player(int playerNumber) {
|
||||
this.playerNumber = playerNumber;
|
||||
currentBet = 0;
|
||||
total = 0;
|
||||
hand = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void setPlayerNumber(int playerNumber) { //TODO: Is this needed if set in constructor?
|
||||
this.playerNumber = playerNumber;
|
||||
}
|
||||
|
||||
public int getPlayerNumber() {
|
||||
return this.playerNumber;
|
||||
}
|
||||
|
||||
public void setCurrentBet(int currentBet) {
|
||||
this.currentBet = currentBet;
|
||||
}
|
||||
@@ -20,22 +34,36 @@ public class Player {
|
||||
return this.currentBet;
|
||||
}
|
||||
|
||||
// TODO replace Player.setTotal with recordWin and recordLoss
|
||||
// recordWin adds 'currentBet' to 'total' and then sets 'currentBet' to zero
|
||||
// recordLoss subtracts 'currentBet' to 'total' and then sets 'currentBet' to zero
|
||||
public void setTotal(int total) {
|
||||
this.total = total;
|
||||
/**
|
||||
* RecordWin adds 'currentBet' to 'total' and then sets 'currentBet' to zero
|
||||
*/
|
||||
public void recordWin() {
|
||||
this.total = this.total + this.currentBet;
|
||||
this.currentBet = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* RecordLoss subtracts 'currentBet' to 'total' and then sets 'currentBet' to zero
|
||||
*/
|
||||
public void recordLoss() {
|
||||
total = total - currentBet;
|
||||
currentBet = 0;
|
||||
}
|
||||
/**
|
||||
* Returns the total of all bets won.
|
||||
* @return Total value
|
||||
*/
|
||||
public int getTotal() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
// TODO replace Player.setHand with 'dealCard(Card card)' and resetHand()
|
||||
// dealCard adds the given card to the player's hand
|
||||
public void dealCard(Card card) {
|
||||
hand.add(card);
|
||||
}
|
||||
|
||||
// resetHand resets 'hand' to an empty list
|
||||
public void setHand(LinkedList<Card> hand) {
|
||||
this.hand = hand;
|
||||
public void resetHand() {
|
||||
this.hand = new LinkedList<>();
|
||||
}
|
||||
|
||||
public LinkedList<Card> getHand() {
|
||||
|
||||
Reference in New Issue
Block a user