mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-25 12:25:10 -08:00
Fixed 2 bugs. 1 yes and no both restarted the game 2. zero is supposed to skip the third card but was treated as an invalid bet.
1. In trying as keep as close to the spirit of the original game as possible, there is no handling for an invalidly low number. A zero input prints "chicken" and skips the third card and starts over with 2 new initial cards. 2. After the wad is blown, anything but a yes answer to the "Try again" question ends the game
This commit is contained in:
@@ -90,19 +90,23 @@ async function main() {
|
||||
print('\nWHAT IS YOUR BET? ');
|
||||
bet = parseInt(await input(), 10);
|
||||
let minimumRequiredBet = 0;
|
||||
if (bet > minimumRequiredBet) {
|
||||
if (bet >= minimumRequiredBet) {
|
||||
if (bet > availableDollars) {
|
||||
print('SORRY, MY FRIEND, BUT YOU BET TOO MUCH.');
|
||||
print(`YOU HAVE ONLY ${availableDollars} DOLLARS TO BET.`);
|
||||
} else {
|
||||
validBet = true;
|
||||
}
|
||||
} else {
|
||||
// Does not meet minimum required bet
|
||||
print('CHICKEN!!');
|
||||
print('');
|
||||
}
|
||||
}
|
||||
if (bet == 0)
|
||||
{
|
||||
// User chose not to bet.
|
||||
print('CHICKEN!!');
|
||||
print('');
|
||||
// Don't draw a third card, draw a new set of 2 cards.
|
||||
continue;
|
||||
}
|
||||
|
||||
print('\n\nHERE IS THE CARD WE DREW: ');
|
||||
print(getCardValue(cardThree));
|
||||
@@ -127,7 +131,7 @@ async function main() {
|
||||
print('');
|
||||
print('');
|
||||
|
||||
if (isValidYesNoString(tryAgainInput)) {
|
||||
if (isValidYesString(tryAgainInput)) {
|
||||
availableDollars = 100;
|
||||
} else {
|
||||
print('O.K., HOPE YOU HAD FUN!');
|
||||
|
||||
Reference in New Issue
Block a user