|
|
@ -22,7 +22,7 @@ impl Screen { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn get_valid_movements(&self, pos: &Point) -> Vec<Point> { |
|
|
|
pub fn get_valid_movements(&self, pos: &Point) -> Vec<Point> { |
|
|
|
let binding = pos.get_neighbors();
|
|
|
|
let binding = pos.get_neighbors(); |
|
|
|
binding |
|
|
|
binding |
|
|
|
.iter() |
|
|
|
.iter() |
|
|
|
.filter(|e| self.is_in_bounds(e)) |
|
|
|
.filter(|e| self.is_in_bounds(e)) |
|
|
@ -31,10 +31,33 @@ impl Screen { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn render(&self, p: &Point, char: &str) { |
|
|
|
pub fn render(&self, p: &Point, char: &str) { |
|
|
|
mvprintw(p.1 + self.center.1, p.0 + self.center.0, char);
|
|
|
|
mvprintw(p.1 + self.center.1, p.0 + self.center.0, char); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn test_in_bounds() { |
|
|
|
|
|
|
|
let x = 20; |
|
|
|
|
|
|
|
let y = 20; |
|
|
|
|
|
|
|
let s = Screen::new(x, y); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert!(&s.is_in_bounds(&Point(0, 0))); |
|
|
|
|
|
|
|
assert!(!&s.is_in_bounds(&Point(21, 0))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
|
|
|
fn test_get_valid_movements_board() { |
|
|
|
|
|
|
|
let x = 20; |
|
|
|
|
|
|
|
let y = 20; |
|
|
|
|
|
|
|
let s = Screen::new(x, y); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let valid = s.get_valid_movements(&Point(0,0)); |
|
|
|
|
|
|
|
assert_eq!(valid, Point(0,0).get_neighbors()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let border = s.get_valid_movements(&Point(19,19)); |
|
|
|
|
|
|
|
assert!(border.len() == 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub enum BoardCommand { |
|
|
|
pub enum BoardCommand { |
|
|
|
Dig(Point), |
|
|
|
Dig(Point), |
|
|
|
LayEgg(Point, u32), |
|
|
|
LayEgg(Point, u32), |
|
|
|