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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum UnitType {
Warrior,
Sludge,
ThickSludge,
Archer,
Captive,
}
impl UnitType {
pub fn draw(self) -> &'static str {
match self {
UnitType::Warrior => "@",
UnitType::Sludge => "s",
UnitType::ThickSludge => "S",
UnitType::Archer => "a",
UnitType::Captive => "C",
}
}
}
#[derive(Clone, Debug)]
pub struct Unit {
pub unit_type: UnitType,
pub position: (i32, i32),
pub hp: (i32, i32),
pub atk: i32,
}
impl Unit {
pub fn new(unit_type: UnitType, position: (i32, i32)) -> Unit {
match unit_type {
UnitType::Warrior => Unit::warrior(position),
UnitType::Sludge => Unit::sludge(position),
UnitType::ThickSludge => Unit::thick_sludge(position),
UnitType::Archer => Unit::archer(position),
UnitType::Captive => Unit::captive(position),
}
}
pub fn warrior(position: (i32, i32)) -> Unit {
Unit {
unit_type: UnitType::Warrior,
position,
hp: (20, 20),
atk: 5,
}
}
pub fn sludge(position: (i32, i32)) -> Unit {
Unit {
unit_type: UnitType::Sludge,
position,
hp: (12, 12),
atk: 3,
}
}
pub fn thick_sludge(position: (i32, i32)) -> Unit {
Unit {
unit_type: UnitType::ThickSludge,
position,
hp: (18, 18),
atk: 3,
}
}
pub fn archer(position: (i32, i32)) -> Unit {
Unit {
unit_type: UnitType::Archer,
position,
hp: (7, 7),
atk: 3,
}
}
pub fn captive(position: (i32, i32)) -> Unit {
Unit {
unit_type: UnitType::Captive,
position,
hp: (1, 1),
atk: 0,
}
}
}