fix(cxxengine): catch errors
This commit is contained in:
parent
4ea4b1249b
commit
1861494048
1 changed files with 8 additions and 3 deletions
|
|
@ -98,7 +98,9 @@ pub fn new_trictrac_engine() -> Box<TricTracEngine> {
|
|||
let mut game_state = GameState::new(false); // schools_enabled = false
|
||||
game_state.init_player("player1");
|
||||
game_state.init_player("player2");
|
||||
game_state.consume(&GameEvent::BeginGame { goes_first: 1 });
|
||||
game_state
|
||||
.consume(&GameEvent::BeginGame { goes_first: 1 })
|
||||
.expect("BeginGame failed during engine initialization");
|
||||
Box::new(TricTracEngine { game_state })
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +191,8 @@ impl TricTracEngine {
|
|||
values: (dice.die1, dice.die2),
|
||||
};
|
||||
self.game_state
|
||||
.consume(&GameEvent::RollResult { player_id, dice });
|
||||
.consume(&GameEvent::RollResult { player_id, dice })
|
||||
.map_err(|e| anyhow::anyhow!(e))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +211,9 @@ impl TricTracEngine {
|
|||
|
||||
match event {
|
||||
Some(evt) if self.game_state.validate(&evt) => {
|
||||
self.game_state.consume(&evt);
|
||||
self.game_state
|
||||
.consume(&evt)
|
||||
.map_err(|e| anyhow::anyhow!(e))?;
|
||||
Ok(())
|
||||
}
|
||||
Some(evt) => anyhow::bail!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue