diff options
author | Tom Barrett <tombarrett@siu.edu> | 2017-10-25 09:56:36 -0500 |
---|---|---|
committer | Tom Barrett <tombarrett@siu.edu> | 2017-10-25 09:56:36 -0500 |
commit | 5c495b75f25c324b5e468d0aa80d0699bb5f3fd2 (patch) | |
tree | 0572763449f700fc407d17f185a2ce1c1495114f /src/list.rs | |
parent | 5b7a80d0e1fc0fcddbfad976a3f0fbbf7f6cd2ab (diff) |
-moved drawing to the map and out of character
-now will just compute free spaces at list level and pass to characters
Diffstat (limited to 'src/list.rs')
-rw-r--r-- | src/list.rs | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/src/list.rs b/src/list.rs index cdf00a8..d622d5c 100644 --- a/src/list.rs +++ b/src/list.rs @@ -4,33 +4,60 @@ use character::Character; use location::Location; pub struct List{ - men : Vec<Character>, - impassable : Vec<Location>, + pub men : Vec<Character>, + impassable_locations : Vec<Location>, } -impl List{ - pub fn new(impassable : Vec<Location>) -> List { +impl List { + pub fn new(impassable_locations : Vec<Location>) -> 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); } - List{ + List { men : men, - impassable : impassable, + impassable_locations : impassable_locations, } } - pub fn draw(&self, window : &pancurses::Window) { - for man in self.men.iter(){ - man.draw(window); + 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); + self.men[i].action(free_locations); } } - pub fn action(&self) { - for man in self.men.iter(){ - man.action(self.men.to_vec(), self.impassable.to_vec()); + fn get_free_locations(&mut self, location : Location) -> Vec<Location> { + let mut potential_locations = Vec::new(); + potential_locations.push(location.up()); + potential_locations.push(location.down()); + potential_locations.push(location.left()); + potential_locations.push(location.right()); + + let mut indexes = Vec::new(); + for man in self.men.iter() { + for (index, potential_location) in potential_locations.iter().enumerate() { + if potential_location == &man.location { + indexes.push(index); + } + } + } + + for impassable_location in self.impassable_locations.iter() { + for (index, potential_location) in potential_locations.iter().enumerate() { + if potential_location == impassable_location { + indexes.push(index); + } + } } + + //for index in indexes.iter() { + // potential_locations.remove(index); + //} + + potential_locations } } |