2022-09-14 18:30:33 +02:00
|
|
|
use crate::data::{Coordinates, GameRules};
|
|
|
|
use rand::RngCore;
|
|
|
|
|
|
|
|
#[derive(Debug, serde::Serialize, serde::Deserialize)]
|
|
|
|
pub struct CurrentGameStatus {
|
|
|
|
pub rules: GameRules,
|
2022-09-15 18:04:22 +02:00
|
|
|
//TODO
|
2022-09-14 18:30:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CurrentGameStatus {
|
|
|
|
/// Check if user can fire at a given location
|
|
|
|
pub fn can_fire_at_location(&self, _location: Coordinates) -> bool {
|
2022-09-15 18:04:22 +02:00
|
|
|
//TODO
|
2022-09-14 18:30:33 +02:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Find valid random fire location. Loop until one is found
|
|
|
|
pub fn find_valid_random_fire_location(&self) -> Coordinates {
|
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
loop {
|
|
|
|
let coordinates = Coordinates::new(
|
|
|
|
(rng.next_u32() % self.rules.map_width as u32) as i32,
|
|
|
|
(rng.next_u32() % self.rules.map_height as u32) as i32,
|
|
|
|
);
|
|
|
|
if coordinates.is_valid(&self.rules) && self.can_fire_at_location(coordinates) {
|
|
|
|
return coordinates;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|