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/character.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/character.rs')
-rw-r--r-- | src/character.rs | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/src/character.rs b/src/character.rs index 7d5e951..2f2289f 100644 --- a/src/character.rs +++ b/src/character.rs @@ -1,14 +1,11 @@ -extern crate pancurses; -use pancurses::ColorPair; - extern crate rand; use character::rand::Rng; use location::Location; pub struct Character{ - symbol : char, - color : u8, + pub symbol : char, + pub color : u8, pub location : Location, } @@ -28,28 +25,12 @@ impl Character { } } - pub fn draw(self, window : &pancurses::Window) { - window.attron(ColorPair(self.color)); - window.mvaddch(self.location.x, self.location.y, self.symbol); - } - - pub fn action(self, men : Vec<Character>, impassable : Vec<Location>){ - self.wander(men, impassable); - } - - fn wander(mut self, men : Vec<Character>, impassable : Vec<Location>){ - let direction = rand::thread_rng().gen_range(0,9); - let mut desired_location = self.location; - if direction == 0 { - desired_location.x = desired_location.x+1; - } - - if self.free_space(desired_location, men, impassable) { - self.location = desired_location; - } + pub fn action(&mut self, free_spaces : Vec<Location>){ + self.wander(free_spaces); } - fn free_space(self, location : Location, men : Vec<Character>, impassable : Vec<Location>) -> bool { - true + fn wander(&mut self, free_spaces : Vec<Location>){ + let direction = rand::thread_rng().gen_range(0,free_spaces.len()); + self.location = free_spaces[direction]; } } |