2022-09-13 17:25:14 +02:00
|
|
|
use crate::data::boats_layout::{BoatsLayout, Coordinates};
|
2022-09-12 16:38:14 +02:00
|
|
|
use crate::data::GameRules;
|
|
|
|
|
|
|
|
enum MapCellContent {
|
|
|
|
Invalid,
|
|
|
|
Nothing,
|
|
|
|
TouchedBoat,
|
|
|
|
Boat,
|
|
|
|
FailedStrike,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MapCellContent {
|
|
|
|
fn letter(&self) -> &'static str {
|
|
|
|
match self {
|
|
|
|
MapCellContent::Invalid => "!",
|
2022-09-13 17:25:14 +02:00
|
|
|
MapCellContent::Nothing => ".",
|
2022-09-12 16:38:14 +02:00
|
|
|
MapCellContent::TouchedBoat => "T",
|
|
|
|
MapCellContent::Boat => "B",
|
|
|
|
MapCellContent::FailedStrike => "X",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct GameMap {
|
|
|
|
rules: GameRules,
|
|
|
|
boats_config: BoatsLayout,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GameMap {
|
|
|
|
pub fn new(rules: GameRules, boats_config: BoatsLayout) -> Self {
|
|
|
|
Self {
|
|
|
|
rules,
|
|
|
|
boats_config,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-13 17:25:14 +02:00
|
|
|
pub fn get_cell_content(&self, c: Coordinates) -> MapCellContent {
|
|
|
|
//TODO : improve this
|
|
|
|
|
|
|
|
if self.boats_config.find_boat_at_position(c).is_some() {
|
|
|
|
return MapCellContent::Boat;
|
|
|
|
}
|
|
|
|
|
2022-09-12 16:38:14 +02:00
|
|
|
return MapCellContent::Nothing;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print_map(&self) {
|
|
|
|
for y in 0..self.rules.map_height {
|
|
|
|
for x in 0..self.rules.map_width {
|
2022-09-13 17:25:14 +02:00
|
|
|
print!(
|
|
|
|
"{} ",
|
|
|
|
self.get_cell_content(Coordinates::new(x as i32, y as i32))
|
|
|
|
.letter()
|
|
|
|
);
|
2022-09-12 16:38:14 +02:00
|
|
|
}
|
|
|
|
println!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|