Can get opponent last fire location
This commit is contained in:
		@@ -60,6 +60,7 @@ pub struct GameScreen {
 | 
			
		||||
    opponent_name: Option<String>,
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user