diff options
| author | Martin Hafskjold Thoresen <martin@vind.ai> | 2025-01-10 18:56:37 +0100 |
|---|---|---|
| committer | Martin Hafskjold Thoresen <martin@vind.ai> | 2025-01-10 18:56:37 +0100 |
| commit | 2f2beb79720ec9fd35b993e7ad907ecf32005cde (patch) | |
| tree | dad61d7971fdf5492631402374581c47df4763e5 | |
| parent | 4b090965a2c76af9c997853c8cc16c643befdceb (diff) | |
| download | musicgame-2f2beb79720ec9fd35b993e7ad907ecf32005cde.tar.gz musicgame-2f2beb79720ec9fd35b993e7ad907ecf32005cde.zip | |
Permute sounds instead of randomly choosing
Also add more sounds
| -rw-r--r-- | src/main.rs | 31 | ||||
| -rw-r--r-- | static/bike.mp3 | bin | 0 -> 33436 bytes | |||
| -rw-r--r-- | static/cough.mp3 | bin | 0 -> 35108 bytes | |||
| -rw-r--r-- | static/o.mp3 | bin | 0 -> 13440 bytes | |||
| -rw-r--r-- | static/pop.mp3 | bin | 0 -> 12480 bytes | |||
| -rw-r--r-- | static/wow.mp3 | bin | 0 -> 10080 bytes |
6 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, diff --git a/static/bike.mp3 b/static/bike.mp3 Binary files differnew file mode 100644 index 0000000..666e194 --- /dev/null +++ b/static/bike.mp3 diff --git a/static/cough.mp3 b/static/cough.mp3 Binary files differnew file mode 100644 index 0000000..a499ad3 --- /dev/null +++ b/static/cough.mp3 diff --git a/static/o.mp3 b/static/o.mp3 Binary files differnew file mode 100644 index 0000000..58fd01e --- /dev/null +++ b/static/o.mp3 diff --git a/static/pop.mp3 b/static/pop.mp3 Binary files differnew file mode 100644 index 0000000..fff12a8 --- /dev/null +++ b/static/pop.mp3 diff --git a/static/wow.mp3 b/static/wow.mp3 Binary files differnew file mode 100644 index 0000000..f3e53dc --- /dev/null +++ b/static/wow.mp3 |
