bet retries on invalid input
This commit is contained in:
parent
0a72da768e
commit
10d00c8ef5
2 changed files with 25 additions and 2 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -9,6 +9,8 @@ fn main() {
|
|||
}
|
||||
|
||||
fn interactive_play() {
|
||||
// TODO: Persist bank between plays
|
||||
// TODO: Make a way to reset bank
|
||||
let mut bank: u64 = 1_000;
|
||||
let mut game = Game::new().with_decks(6);
|
||||
let mut last_bet: Option<u32> = None;
|
||||
|
|
@ -26,12 +28,18 @@ fn interactive_play() {
|
|||
if input == "" {
|
||||
bet = last_bet.unwrap();
|
||||
} else {
|
||||
bet = input.parse().unwrap();
|
||||
match input.parse() {
|
||||
Ok(b) => bet = b,
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print!("Your bet? ");
|
||||
io::stdout().flush().unwrap();
|
||||
bet = read_input().parse().unwrap();
|
||||
match read_input().parse() {
|
||||
Ok(b) => bet = b,
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
if bet as u64 <= bank {
|
||||
break;
|
||||
|
|
@ -58,6 +66,9 @@ fn interactive_play() {
|
|||
PlayResult::DealerBlackjack => println!("Dealer got blackjack"),
|
||||
PlayResult::Bust => println!("You busted"),
|
||||
}
|
||||
if result.shuffled {
|
||||
println!("Deck was shuffled at beginning of round");
|
||||
}
|
||||
|
||||
bank += result.player_winnings;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue