|
@@ -1,4 +1,6 @@
|
|
use std::collections::BTreeMap;
|
|
use std::collections::BTreeMap;
|
|
|
|
+use std::sync::Arc;
|
|
|
|
+use std::borrow::Borrow;
|
|
|
|
|
|
use rand::thread_rng;
|
|
use rand::thread_rng;
|
|
use rand::seq::SliceRandom;
|
|
use rand::seq::SliceRandom;
|
|
@@ -28,7 +30,9 @@ pub struct GameLobby {
|
|
waiting_players: BTreeMap<String, Addr<GameConnection>>,
|
|
waiting_players: BTreeMap<String, Addr<GameConnection>>,
|
|
ready_players: Vec<String>,
|
|
ready_players: Vec<String>,
|
|
lobby_state: LobbyState,
|
|
lobby_state: LobbyState,
|
|
- data_source: Box<dyn datasource::DataSource<String>>,
|
|
|
|
|
|
+
|
|
|
|
+ //data_source: Arc<dyn datasource::DataSource<String>>,
|
|
|
|
+ shuffler: datasource::Shuffler<String>
|
|
}
|
|
}
|
|
|
|
|
|
impl Actor for GameLobby {
|
|
impl Actor for GameLobby {
|
|
@@ -96,7 +100,7 @@ impl Handler<SubmitGuessMsg> for GameLobby {
|
|
}
|
|
}
|
|
|
|
|
|
impl GameLobby {
|
|
impl GameLobby {
|
|
- pub fn new(gi: String) -> Self {
|
|
|
|
|
|
+ pub fn new(gi: String, data_source: Arc<dyn datasource::DataSource<String>>) -> Self {
|
|
GameLobby {
|
|
GameLobby {
|
|
connected_players: BTreeMap::new(),
|
|
connected_players: BTreeMap::new(),
|
|
game_id: gi,
|
|
game_id: gi,
|
|
@@ -104,12 +108,13 @@ impl GameLobby {
|
|
waiting_players: BTreeMap::new(),
|
|
waiting_players: BTreeMap::new(),
|
|
ready_players: Vec::new(),
|
|
ready_players: Vec::new(),
|
|
lobby_state: LobbyState::Starting,
|
|
lobby_state: LobbyState::Starting,
|
|
- data_source: Box::new(datasource::ArraySource::create(vec![
|
|
|
|
|
|
+ shuffler: datasource::Shuffler::create(data_source)
|
|
|
|
+ /*Box::new(datasource::ArraySource::create(vec![
|
|
"Delikatessfutter für Hunde".to_owned(),
|
|
"Delikatessfutter für Hunde".to_owned(),
|
|
"Ein Hotel für die ganze Familie".to_owned(),
|
|
"Ein Hotel für die ganze Familie".to_owned(),
|
|
"Brasilianischer Superstar".to_owned(),
|
|
"Brasilianischer Superstar".to_owned(),
|
|
"Buchstabe des griechischen Alphabets".to_owned(),
|
|
"Buchstabe des griechischen Alphabets".to_owned(),
|
|
- ]))
|
|
|
|
|
|
+ ]))*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -124,12 +129,9 @@ impl GameLobby {
|
|
self.ready_players.clear();
|
|
self.ready_players.clear();
|
|
},
|
|
},
|
|
LobbyState::Creating => {
|
|
LobbyState::Creating => {
|
|
- let ds = &self.data_source;
|
|
|
|
|
|
+ let s = &mut self.shuffler;
|
|
let mut index = 0;
|
|
let mut index = 0;
|
|
- self.game.start_round(|| {
|
|
|
|
- index += 1;
|
|
|
|
- ds.get_ith(index - 1).unwrap().clone()
|
|
|
|
- });
|
|
|
|
|
|
+ self.game.start_round(|| s.get());
|
|
},
|
|
},
|
|
_ => {}
|
|
_ => {}
|
|
}
|
|
}
|