blob: 4c7f7dc296c1840e131dee5d97a3a6017565ffe7 (
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
|
extern crate rand;
use character::rand::Rng;
use location::Location;
pub struct Character{
pub symbol : char,
pub 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 action(&mut self, free_spaces : Vec<Location>) {
self.wander(free_spaces);
}
fn wander(&mut self, free_spaces : Vec<Location>) {
let direction = rand::thread_rng().gen_range(0, free_spaces.len());
self.location = free_spaces[direction];
}
}
|