summaryrefslogtreecommitdiffstats
path: root/src/bin/client/repl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/client/repl.rs')
-rw-r--r--src/bin/client/repl.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/bin/client/repl.rs b/src/bin/client/repl.rs
index 91fd10e..dfcf0d2 100644
--- a/src/bin/client/repl.rs
+++ b/src/bin/client/repl.rs
@@ -6,6 +6,7 @@ use std::time::Instant;
6use crate::connection::TlsStream; 6use crate::connection::TlsStream;
7use crate::database; 7use crate::database;
8use crate::games::manager::GameManager; 8use crate::games::manager::GameManager;
9use crate::games::traits::GamePhase;
9 10
10use crossterm::{ 11use crossterm::{
11 cursor::{Hide, MoveToColumn, Show}, 12 cursor::{Hide, MoveToColumn, Show},
@@ -77,12 +78,15 @@ impl ClientState {
77 return true; 78 return true;
78 } 79 }
79 KeyCode::Char(' ') => { 80 KeyCode::Char(' ') => {
80 let should_start = !self.game_manager.is_game_started(); 81 let can_spin = self.game_manager.get_current_state()
81 if should_start { 82 .map(|s| s.phase == GamePhase::WaitingToStart || s.phase == GamePhase::Finished)
83 .unwrap_or(false);
84 if can_spin {
82 if let Some(mut stream) = self.stream.take() { 85 if let Some(mut stream) = self.stream.take() {
83 match self.game_manager.start_game(&mut stream) { 86 match self.game_manager.start_game(&mut stream) {
84 Ok(()) => { 87 Ok(()) => {
85 self.play_spin_animation(&mut stream); 88 self.play_spin_animation(&mut stream);
89 self.game_manager.reset_phase_to_waiting();
86 } 90 }
87 Err(e) => println!("\nError starting game: {:?}", e), 91 Err(e) => println!("\nError starting game: {:?}", e),
88 } 92 }