diff --git a/server/src/game.rs b/server/src/game.rs index 8235ed8..7afded3 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -78,6 +78,10 @@ pub struct Game { pub white_discard: Vec>, /// Black draw pile pub black: Vec>, + + // TODO: do this better + rotation: Vec, + rotation_index: usize, } impl Game { @@ -129,6 +133,8 @@ impl Game { judge_pile_meta: HashMap::new(), judge_pile: HashMap::new(), white_discard: vec![], + rotation: vec![], // this gets set in create_user() + rotation_index: 0, } } @@ -233,6 +239,23 @@ impl Game { .map(|pair| pair.1) .collect::>>(), ); + + tracing::debug!("{:#?}", self.rotation); + tracing::debug!("{:#?}", self.rotation_index); + // Choose new czar + if self.rotation_index == self.rotation.len() { + self.rotation_index = 0; + } else { + self.rotation_index += 1; + } + tracing::debug!("{:#?}", self.rotation); + tracing::debug!("{:#?}", self.rotation_index); + self.czar = self + .players + .get(&self.rotation[self.rotation_index]) + .unwrap() + .user + .clone(); } /// Draw one black card at random from play deck. @@ -279,5 +302,8 @@ impl Game { // Add player to game self.players .insert(user.read().unwrap().uuid.clone(), new_player); + + // Add player to rotation + self.rotation.push(user.read().unwrap().uuid.to_string()); } } diff --git a/server/src/game_handler.rs b/server/src/game_handler.rs index 4ca4807..b870fd6 100644 --- a/server/src/game_handler.rs +++ b/server/src/game_handler.rs @@ -235,7 +235,7 @@ impl GameHandler { name: this_game.read().unwrap().name.clone(), host: this_game.read().unwrap().host.read().unwrap().name.clone(), players: players.clone(), - czar: this_game.read().unwrap().host.read().unwrap().name.clone(), + czar: this_game.read().unwrap().czar.read().unwrap().name.clone(), black: ( this_game.read().unwrap().current_black.text.clone(), this_game.read().unwrap().current_black.pick,