use crate::data::boats_layout::{BoatsLayout, Coordinates}; use crate::data::GameRules; pub enum MapCellContent { Invalid, Nothing, TouchedBoat, Boat, FailedStrike, } impl MapCellContent { fn letter(&self) -> &'static str { match self { MapCellContent::Invalid => "!", MapCellContent::Nothing => ".", 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, } } 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; } MapCellContent::Nothing } pub fn print_map(&self) { for y in 0..self.rules.map_height { for x in 0..self.rules.map_width { print!( "{} ", self.get_cell_content(Coordinates::new(x as i32, y as i32)) .letter() ); } println!(); } } }