wip mirror
This commit is contained in:
parent
f1461985ac
commit
f9f4405943
3 changed files with 61 additions and 18 deletions
|
|
@ -733,6 +733,58 @@ impl GameEvent {
|
|||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mirror(&self) -> Self {
|
||||
// let mut mirror = self.clone();
|
||||
let mirror_player_id = if let Some(player_id) = self.player_id() {
|
||||
if player_id == 1 {
|
||||
2
|
||||
} else {
|
||||
1
|
||||
}
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
match self {
|
||||
Self::PlayerJoined { player_id: _, name } => Self::PlayerJoined {
|
||||
player_id: mirror_player_id,
|
||||
name: name.clone(),
|
||||
},
|
||||
Self::PlayerDisconnected { player_id: _ } => GameEvent::PlayerDisconnected {
|
||||
player_id: mirror_player_id,
|
||||
},
|
||||
Self::Roll { player_id: _ } => GameEvent::Roll {
|
||||
player_id: mirror_player_id,
|
||||
},
|
||||
Self::RollResult { player_id: _, dice } => GameEvent::RollResult {
|
||||
player_id: mirror_player_id,
|
||||
dice: *dice,
|
||||
},
|
||||
Self::Mark {
|
||||
player_id: _,
|
||||
points,
|
||||
} => GameEvent::Mark {
|
||||
player_id: mirror_player_id,
|
||||
points: *points,
|
||||
},
|
||||
Self::Go { player_id: _ } => GameEvent::Go {
|
||||
player_id: mirror_player_id,
|
||||
},
|
||||
Self::Move {
|
||||
player_id: _,
|
||||
moves: (move1, move2),
|
||||
} => Self::Move {
|
||||
player_id: mirror_player_id,
|
||||
moves: (move1.mirror(), move2.mirror()),
|
||||
},
|
||||
Self::BeginGame { goes_first } => GameEvent::BeginGame {
|
||||
goes_first: (if *goes_first == 1 { 2 } else { 1 }),
|
||||
},
|
||||
Self::EndGame { reason } => GameEvent::EndGame { reason: *reason },
|
||||
Self::PlayError => GameEvent::PlayError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue