From 1c3ec15a9a8b7cef3c544af225d028b3de13d75e Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Thu, 2 Nov 2017 08:36:26 -0500 Subject: - added color constants, fixed some syntax, and changed method of getting potential locations --- src/list.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/list.rs') diff --git a/src/list.rs b/src/list.rs index 23d23df..cf0607f 100644 --- a/src/list.rs +++ b/src/list.rs @@ -1,7 +1,8 @@ extern crate pancurses; -use character::Character; use location::Location; +use character::Character; +use constants::Colors; pub struct List{ pub men : Vec, @@ -12,9 +13,7 @@ impl List { pub fn new(impassable_locations : Vec) -> List { let mut men = Vec::new(); for i in 0..3 { - let l = Location{x:150,y:150+i}; - let c = Character::new('@',4,l); - men.push(c); + men.push(Character::new('@', Colors::BlueUnit as u8, Location{ x : 150, y : 150+i })); } List { men : men, @@ -24,22 +23,14 @@ impl List { pub fn action(&mut self) { for i in 0..self.men.len() { - let tmp = self.men[i].location.clone(); - let free_locations = self.get_free_locations(tmp); + let location = self.men[i].location.clone(); + let free_locations = self.get_free_locations(location); self.men[i].action(free_locations); } } fn get_free_locations(&mut self, location : Location) -> Vec { - let mut potential_locations = Vec::new(); - potential_locations.push(location.up()); - potential_locations.push(location.upleft()); - potential_locations.push(location.upright()); - potential_locations.push(location.down()); - potential_locations.push(location.downleft()); - potential_locations.push(location.downright()); - potential_locations.push(location.left()); - potential_locations.push(location.right()); + let mut potential_locations = location.get_around(); potential_locations.retain(|potential_location| { let mut keep = true; -- cgit v1.2.3