mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-26 12:51:29 -08:00
Test insurance collection
This commit is contained in:
@@ -75,20 +75,7 @@ public class Game {
|
||||
printInitialDeal(players, dealer);
|
||||
|
||||
if(dealer.getHand().get(0).getValue() == 1) {
|
||||
boolean isInsurance = userIo.promptBoolean("ANY INSURANCE");
|
||||
if(isInsurance) {
|
||||
userIo.println("INSURANCE BETS");
|
||||
for(Player player : players) {
|
||||
while(true) {
|
||||
double insuranceBet = userIo.promptDouble("# " + player.getPlayerNumber() + " ");
|
||||
// 0 indicates no insurance for that player.
|
||||
if(insuranceBet >= 0 && insuranceBet <= player.getCurrentBet()) {
|
||||
player.setInsuranceBet(insuranceBet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
collectInsurance(players);
|
||||
}
|
||||
|
||||
if(ScoringUtils.scoreHand(dealer.getHand()) == 21) {
|
||||
@@ -113,6 +100,23 @@ public class Game {
|
||||
}
|
||||
}
|
||||
|
||||
protected void collectInsurance(Iterable<Player> players) {
|
||||
boolean isInsurance = userIo.promptBoolean("ANY INSURANCE");
|
||||
if(isInsurance) {
|
||||
userIo.println("INSURANCE BETS");
|
||||
for(Player player : players) {
|
||||
while(true) {
|
||||
double insuranceBet = userIo.promptDouble("# " + player.getPlayerNumber() + " ");
|
||||
// 0 indicates no insurance for that player.
|
||||
if(insuranceBet >= 0 && insuranceBet <= (player.getCurrentBet() / 2)) {
|
||||
player.setInsuranceBet(insuranceBet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the cards for each player and the up card for the dealer.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user