Skip to main content

interactive/
interactive.rs

1use rock_paper_scissors::{PlayerMoves, Scores, Winner, GameSettings};
2
3fn main() {
4    let mut scores = Scores::new();
5
6    let game_settings = GameSettings::from_first_to(3);
7
8    println!("Welcome to Rock-Paper-Scissors!");
9
10    // Game loop
11    while scores.check_for_winner(&game_settings).is_err() {
12        let player_moves = PlayerMoves::build_from_input();
13
14        let round_winner = player_moves.check_who_wins_round();
15        println!(
16            "You chose {}. Enemy chose {}.",
17            player_moves.user_move.convert_to_string(),
18            player_moves.enemy_move.convert_to_string(),
19        );
20        println!("Result: {}", round_winner.convert_to_string());
21
22        // Update scores
23        match round_winner {
24            Winner::User => scores.user_wins += 1,
25            Winner::Enemy => scores.enemy_wins += 1,
26            Winner::Tie => (),
27        }
28
29        println!(
30            "Current Scores -> You: {}, Enemy: {}",
31            scores.user_wins, scores.enemy_wins
32        );
33    }
34
35    // Display final results
36    let game_winner = scores.check_for_winner(&game_settings).unwrap();
37    println!("Game over! {}", game_winner.convert_to_string());
38}