From 1e77601579065df48a9b1d9daa9dba46522842ca Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Mon, 23 Oct 2017 11:57:59 -0500 Subject: -decent starting point, but centering does not seem to be working --- src/character.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/character.rs (limited to 'src/character.rs') diff --git a/src/character.rs b/src/character.rs new file mode 100644 index 0000000..7d5e951 --- /dev/null +++ b/src/character.rs @@ -0,0 +1,55 @@ +extern crate pancurses; +use pancurses::ColorPair; + +extern crate rand; +use character::rand::Rng; + +use location::Location; + +pub struct Character{ + symbol : char, + color : u8, + pub location : Location, +} + +impl Copy for Character {} +impl Clone for Character { + fn clone(&self) -> Character { + *self + } +} + +impl Character { + pub fn new(symbol : char, color : u8, location : Location) -> Character { + Character { + symbol : symbol, + color : color, + location : location, + } + } + + 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, impassable : Vec){ + self.wander(men, impassable); + } + + fn wander(mut self, men : Vec, impassable : Vec){ + 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; + } + } + + fn free_space(self, location : Location, men : Vec, impassable : Vec) -> bool { + true + } +} -- cgit v1.2.3