Can get opponent last fire location

This commit is contained in:
Pierre HUBERT 2022-10-15 16:33:45 +02:00
parent b832ef82ed
commit a2c880814c
2 changed files with 15 additions and 1 deletions

View File

@ -60,6 +60,7 @@ pub struct GameScreen {
opponent_name: Option<String>, opponent_name: Option<String>,
game: CurrentGameStatus, game: CurrentGameStatus,
curr_shoot_position: Coordinates, curr_shoot_position: Coordinates,
last_opponent_fire_position: Coordinates,
} }
impl GameScreen { impl GameScreen {
@ -70,6 +71,7 @@ impl GameScreen {
opponent_name: None, opponent_name: None,
game: Default::default(), game: Default::default(),
curr_shoot_position: Coordinates::new(0, 0), curr_shoot_position: Coordinates::new(0, 0),
last_opponent_fire_position: Coordinates::invalid(),
} }
} }
@ -193,7 +195,10 @@ impl GameScreen {
} }
ServerMessage::FireResult { .. } => {} ServerMessage::FireResult { .. } => {}
ServerMessage::OpponentFireResult { .. } => {}
ServerMessage::OpponentFireResult { pos, .. } => {
self.last_opponent_fire_position = pos;
}
ServerMessage::LostGame { .. } => {} ServerMessage::LostGame { .. } => {}
ServerMessage::WonGame { .. } => {} ServerMessage::WonGame { .. } => {}
@ -238,6 +243,11 @@ impl GameScreen {
}, },
cells: vec![self.curr_shoot_position], cells: vec![self.curr_shoot_position],
}); });
} else {
map_widget = map_widget.add_colored_cells(ColoredCells {
color: Color::Green,
cells: vec![self.last_opponent_fire_position],
});
} }
// Sunk boats // Sunk boats

View File

@ -85,6 +85,10 @@ impl Coordinates {
} }
} }
pub fn invalid() -> Self {
Self { x: -1, y: -1 }
}
pub fn is_valid(&self, rules: &GameRules) -> bool { pub fn is_valid(&self, rules: &GameRules) -> bool {
self.x >= 0 self.x >= 0
&& self.y >= 0 && self.y >= 0