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
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::actions::Action;
pub struct Warrior {
path_clear: bool,
captive_found: bool,
health: i32,
pub action: Option<Action>,
}
impl Warrior {
pub fn new(path_clear: bool, captive_found: bool, health: i32) -> Warrior {
Warrior {
path_clear,
captive_found,
health,
action: None,
}
}
pub fn walk(&mut self) {
self.perform(Action::Walk);
}
pub fn path_clear(&self) -> bool {
self.path_clear
}
pub fn captive_found(&self) -> bool {
self.captive_found
}
pub fn attack(&mut self) {
self.perform(Action::Attack);
}
pub fn health(&self) -> i32 {
self.health
}
pub fn rest(&mut self) {
self.perform(Action::Rest);
}
pub fn rescue(&mut self) {
self.perform(Action::Rescue);
}
fn perform(&mut self, action: Action) {
if self.action.is_some() {
println!("Warrior already performed action!");
return;
}
self.action = Some(action);
}
}