update mockrooms so join emits join message

This commit is contained in:
bel
2020-05-03 09:22:23 -06:00
parent 42414a0a23
commit dca8d756cd
9 changed files with 233 additions and 57 deletions

View File

@@ -1,32 +1,45 @@
/*
use super::super::super::model::state::room::Room;
use super::lobby::Lobby;
pub struct GameMaster {
room: Box<dyn Room>,
lobby: Lobby,
}
impl GameMaster {
fn new(room: Box<dyn Room>) -> GameMaster {
GameMaster{
room: room,
lobby: Lobby::new(),
}
}
fn run(&self) -> Result<String, String> {
fn run(&mut self) -> Result<String, String> {
self.run_lobby()?;
self.run_game_setup()?;
self.run_game()
}
fn run_lobby(&self) -> Result<String, String> {
fn run_lobby(&mut self) -> Result<String, String> {
println!(". run lobby");
loop {
let rollback = self.room.since();
let events = self.room.sync();
println!(". rollback: {:?}", rollback);
for e in &events {
println!("e: {:?}", e);
}
self.room.rollback(rollback);
break
}
Err("not impl".to_string())
}
fn run_game_setup(&self) -> Result<String, String> {
fn run_game_setup(&mut self) -> Result<String, String> {
Err("not impl".to_string())
}
fn run_game(&self) -> Result<String, String> {
fn run_game(&mut self) -> Result<String, String> {
Err("not impl".to_string())
}
}
@@ -63,21 +76,25 @@ mod tests {
}
#[test]
fn gm_run_lobby_fail() {
fn run_lobby() {
let mut mrs = MockRooms::new();
let mut r1 = mrs.create();
let room_id = r1.room_id();
let mut gm = GameMaster::new(r1);
let mut r2 = mrs.join(room_id).unwrap();
gm.run_lobby();
assert!(gm.lobby.players.len() == 1, "players: {:?}, sync: {:?}", gm.lobby.players, gm.room.sync());
}
#[test]
fn run_game_setup_fail() {
let gm = GameMaster::new(Box::new(MockRoom::create()));
panic!("not impl");
}
#[test]
fn gm_run_game_setup_fail() {
let gm = GameMaster::new(Box::new(MockRoom::create()));
panic!("not impl");
}
#[test]
fn gm_run_game_fail() {
fn run_game_fail() {
let gm = GameMaster::new(Box::new(MockRoom::create()));
panic!("not impl");
}
}
*/