From a2c880814c21e26bef275b83046297e1eeb80296 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Sat, 15 Oct 2022 16:33:45 +0200 Subject: [PATCH] Can get opponent last fire location --- rust/cli_player/src/ui_screens/game_screen.rs | 12 +++++++++++- rust/sea_battle_backend/src/data/boats_layout.rs | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/rust/cli_player/src/ui_screens/game_screen.rs b/rust/cli_player/src/ui_screens/game_screen.rs index fd76d50..60280de 100644 --- a/rust/cli_player/src/ui_screens/game_screen.rs +++ b/rust/cli_player/src/ui_screens/game_screen.rs @@ -60,6 +60,7 @@ pub struct GameScreen { opponent_name: Option, game: CurrentGameStatus, curr_shoot_position: Coordinates, + last_opponent_fire_position: Coordinates, } impl GameScreen { @@ -70,6 +71,7 @@ impl GameScreen { opponent_name: None, game: Default::default(), curr_shoot_position: Coordinates::new(0, 0), + last_opponent_fire_position: Coordinates::invalid(), } } @@ -193,7 +195,10 @@ impl GameScreen { } ServerMessage::FireResult { .. } => {} - ServerMessage::OpponentFireResult { .. } => {} + + ServerMessage::OpponentFireResult { pos, .. } => { + self.last_opponent_fire_position = pos; + } ServerMessage::LostGame { .. } => {} ServerMessage::WonGame { .. } => {} @@ -238,6 +243,11 @@ impl GameScreen { }, 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 diff --git a/rust/sea_battle_backend/src/data/boats_layout.rs b/rust/sea_battle_backend/src/data/boats_layout.rs index fc3e45f..b3b141c 100644 --- a/rust/sea_battle_backend/src/data/boats_layout.rs +++ b/rust/sea_battle_backend/src/data/boats_layout.rs @@ -85,6 +85,10 @@ impl Coordinates { } } + pub fn invalid() -> Self { + Self { x: -1, y: -1 } + } + pub fn is_valid(&self, rules: &GameRules) -> bool { self.x >= 0 && self.y >= 0