mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-03 08:37:59 -08:00
Handle 'an' vs 'a' grammar
This commit is contained in:
@@ -61,6 +61,19 @@ public final class Card {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the value of {@link #toString()} preceded by either "AN " or "A " depending on which is gramatically correct.
|
||||||
|
*
|
||||||
|
* @return "AN [x]" when [x] is "an" ace or "an" 8, and "A [X]" otherwise.
|
||||||
|
*/
|
||||||
|
public String toProseString() {
|
||||||
|
if(value == 1 || value == 8) {
|
||||||
|
return "AN " + toString();
|
||||||
|
} else {
|
||||||
|
return "A " + toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
// Overriding 'equals' and 'hashCode' (below) make your class work correctly
|
// Overriding 'equals' and 'hashCode' (below) make your class work correctly
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(ScoringUtils.scoreHand(dealer.getHand()) == 21) {
|
if(ScoringUtils.scoreHand(dealer.getHand()) == 21) {
|
||||||
userIo.println("DEALER HAS A " + dealer.getHand().get(1).toString() + " IN THE HOLE");
|
userIo.println("DEALER HAS " + dealer.getHand().get(1).toProseString() + " IN THE HOLE");
|
||||||
userIo.println("FOR BLACKJACK");
|
userIo.println("FOR BLACKJACK");
|
||||||
} else {
|
} else {
|
||||||
Card dealerFirstCard = dealer.getHand().get(0);
|
Card dealerFirstCard = dealer.getHand().get(0);
|
||||||
@@ -176,7 +176,7 @@ public class Game {
|
|||||||
userIo.println("...BUSTED");
|
userIo.println("...BUSTED");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
action = userIo.prompt("RECEIVED A " + c.toString() + " HIT");
|
action = userIo.prompt("RECEIVED " + c.toProseString() + " HIT");
|
||||||
} else if(action.equalsIgnoreCase("S")){ // STAY
|
} else if(action.equalsIgnoreCase("S")){ // STAY
|
||||||
break;
|
break;
|
||||||
} else if(action.equalsIgnoreCase("D") && player.canDoubleDown(handNumber)) { // DOUBLE DOWN
|
} else if(action.equalsIgnoreCase("D") && player.canDoubleDown(handNumber)) { // DOUBLE DOWN
|
||||||
@@ -186,7 +186,7 @@ public class Game {
|
|||||||
userIo.println("...BUSTED");
|
userIo.println("...BUSTED");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
userIo.println("RECEIVED A " + c.toString());
|
userIo.println("RECEIVED " + c.toProseString());
|
||||||
break;
|
break;
|
||||||
} else if(action.equalsIgnoreCase("/")) { // SPLIT
|
} else if(action.equalsIgnoreCase("/")) { // SPLIT
|
||||||
if(player.isSplit()) {
|
if(player.isSplit()) {
|
||||||
@@ -198,20 +198,11 @@ public class Game {
|
|||||||
player.split();
|
player.split();
|
||||||
Card card = deck.deal();
|
Card card = deck.deal();
|
||||||
player.dealCard(card, 1);
|
player.dealCard(card, 1);
|
||||||
// TODO move the "a" vs "an" logic to userIo or Card
|
userIo.println("FIRST HAND RECEIVES " + card.toProseString());
|
||||||
if(card.getValue() == 1 || card.getValue() == 8) {
|
|
||||||
userIo.println("FIRST HAND RECEIVES AN " + card.toString());
|
|
||||||
} else {
|
|
||||||
userIo.println("FIRST HAND RECEIVES A " + card.toString());
|
|
||||||
}
|
|
||||||
play(player, 1);
|
play(player, 1);
|
||||||
card = deck.deal();
|
card = deck.deal();
|
||||||
player.dealCard(card, 2);
|
player.dealCard(card, 2);
|
||||||
if(card.getValue() == 1 || card.getValue() == 8) {
|
userIo.println("SECOND HAND RECEIVES " + card.toProseString());
|
||||||
userIo.println("SECOND HAND RECEIVES AN " + card.toString());
|
|
||||||
} else {
|
|
||||||
userIo.println("SECOND HAND RECEIVES A " + card.toString());
|
|
||||||
}
|
|
||||||
play(player, 2);
|
play(player, 2);
|
||||||
return; // Don't fall out of the while loop and print another total
|
return; // Don't fall out of the while loop and print another total
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user