1use colored::Colorize;
2use rock_paper_scissors::*;
3
4fn main() {
5 println!("{}", "Welcome to rock paper scissors!".blue().bold());
6
7 let game_settings = GameSettings::from_first_to(3);
9
10 println!("{}", "Game will be first to 3 rounds.".blue().bold());
11
12 let mut scores = Scores::new(); let mut round_counter = 0;
15
16 while scores.check_for_winner(&game_settings).is_err() { round_counter += 1;
18 let player_moves = PlayerMoves::build_from_input(); let round_winner = player_moves.check_who_wins_round(); println!(
22 "{}{}{}",
23 "-----Round ".magenta(),
24 round_counter.to_string().magenta(),
25 "-----".magenta()
26 );
27
28 println!(
29 "{}{}{}{}{}",
30 "User: ".italic(),
31 player_moves.user_move.convert_to_string().italic(),
32 " :: ".italic(),
33 "Enemy: ".italic(),
34 player_moves.enemy_move.convert_to_string().italic()
35 );
36
37
38 match round_winner {
39 Winner::Tie => {
40 println!("{}", "It's a tie!".blue());
41 round_counter -= 1;
42 },
43 Winner::User => {
44 println!("{}", "You win!".green());
45 scores.user_wins += 1;
46 },
47 Winner::Enemy => {
48 println!("{}", "Enemy wins!".red());
49 scores.enemy_wins += 1;
50 }
51 }
52
53 println!("{}", "[Scores]".magenta().bold());
55 println!("{}{}", "User: ".magenta(), scores.user_wins.to_string().magenta());
56 println!("{}{}", "Enemy: ".magenta(), scores.enemy_wins.to_string().magenta());
57 }
58
59
60 if scores.check_for_winner(&game_settings) == Ok(Winner::User) {
61 println!("{}", "You won the game!".green());
62 } else {
63 println!("{}", "You lost the game!".red());
64 }
65
66}