summaryrefslogtreecommitdiff
path: root/src/character.rs
blob: 7d5e95192ad4f9008e175149502d643a50b80760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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<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;
        }
    }

    fn free_space(self, location : Location, men : Vec<Character>, impassable : Vec<Location>) -> bool {
        true
    }
}