diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index caf01c4..a6963c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,7 @@ struct Game { next_rounds: Vec<UserId>, /// Data for each round rounds: Vec<Round>, + user_to_sound: HashMap<UserId, String>, /// Sender to broadcast things broadcast_tx: Sender<String>, @@ -140,6 +141,26 @@ impl Game { info!("All users have submitted"); let users = self.submissions.keys().cloned(); self.next_rounds = users.collect(); + + let mut rng = rand::thread_rng(); + let sound_fx = [ + "cough.mp3", + "wow.mp3", + "cat.mp3", + "pop.mp3", + "car.mp3", + "bike.mp3", + "dog.mp3", + "o.mp3", + ] + .choose_multiple(&mut rng, self.next_rounds.len()); + self.user_to_sound = self + .next_rounds + .iter() + .zip(sound_fx) + .map(|(u, s)| (*u, s.to_string())) + .collect(); + self.new_round(); } else { self.message_screen(uid, self.screen_submitted()) @@ -154,10 +175,11 @@ impl Game { return; }; - let mut rng = rand::thread_rng(); - let sound_fx = ["dog.mp3", "cat.mp3", "car.mp3"] - .choose(&mut rng) - .expect("not empty"); + let sound_fx = self + .user_to_sound + .get(&uid) + .cloned() + .unwrap_or_else(|| format!("cough.mp3")); self.rounds.push(Round { author: uid, @@ -424,6 +446,7 @@ impl ServerState { active_users: HashSet::new(), submissions: HashMap::new(), next_rounds: Vec::new(), + user_to_sound: HashMap::new(), rounds: Vec::new(), broadcast_rx: rx, broadcast_tx: tx, |
