extract method
This commit is contained in:
parent
61f6d56942
commit
77f8a7bf0c
2 changed files with 13 additions and 7 deletions
|
|
@ -115,7 +115,7 @@ impl City {
|
|||
for wonder in self.city_pieces.wonders.iter() {
|
||||
(wonder.player_deinitializer)(old_player);
|
||||
(wonder.player_initializer)(new_player);
|
||||
old_player.remove_wonder(&wonder);
|
||||
old_player.remove_wonder(wonder);
|
||||
new_player.wonders.push(wonder.name.clone());
|
||||
}
|
||||
if let Some(player) = &self.city_pieces.obelisk {
|
||||
|
|
|
|||
|
|
@ -161,6 +161,15 @@ impl Game {
|
|||
self.execute_playing_action(action, player_index);
|
||||
}
|
||||
|
||||
pub fn with_player<F>(&mut self, player_index: usize, action: F)
|
||||
where
|
||||
F: FnOnce(&mut Player, &mut Game),
|
||||
{
|
||||
let mut player = self.players.remove(player_index);
|
||||
action(&mut player, self);
|
||||
self.players.insert(player_index, player);
|
||||
}
|
||||
|
||||
fn execute_playing_action(&mut self, action: String, player_index: usize) {
|
||||
let playing_action =
|
||||
serde_json::from_str(&action).expect("action should be valid playing action json");
|
||||
|
|
@ -183,9 +192,7 @@ impl Game {
|
|||
self.played_limited_actions.push(name.clone());
|
||||
}
|
||||
}
|
||||
let mut player = self.players.remove(player_index);
|
||||
action.execute(&mut player, self);
|
||||
self.players.insert(player_index, player);
|
||||
self.with_player(player_index, |p, g| action.execute(p, g));
|
||||
if !free_action {
|
||||
self.actions_left -= 1;
|
||||
}
|
||||
|
|
@ -201,9 +208,8 @@ impl Game {
|
|||
self.log.push(LogItem::StatusPhaseAction(
|
||||
serde_json::to_string(&action).expect("status phase action should be serializable"),
|
||||
));
|
||||
let mut player = self.players.remove(player_index);
|
||||
action.execute(&mut player, self);
|
||||
self.players.insert(player_index, player);
|
||||
|
||||
self.with_player(player_index, |p, g| action.execute(p, g));
|
||||
if matches!(phase, DetermineFirstPlayer) {
|
||||
self.next_age();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue