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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use crate::Direction;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum UnitType {
    Archer,
    Captive,
    Sludge,
    ThickSludge,
    Warrior,
    Wizard,
}
impl UnitType {
    
    pub fn draw(self) -> &'static str {
        match self {
            UnitType::Archer => "a",
            UnitType::Captive => "C",
            UnitType::Sludge => "s",
            UnitType::ThickSludge => "S",
            UnitType::Warrior => "@",
            UnitType::Wizard => "w",
        }
    }
}
#[derive(Clone, Debug)]
pub struct Unit {
    pub unit_type: UnitType,
    pub position: (i32, i32),
    pub hp: (i32, i32),
    pub atk: i32,
    pub facing: Option<Direction>,
}
impl Unit {
    
    pub fn new(unit_type: UnitType, position: (i32, i32)) -> Unit {
        match unit_type {
            UnitType::Archer => Unit::archer(position),
            UnitType::Captive => Unit::captive(position),
            UnitType::Sludge => Unit::sludge(position),
            UnitType::ThickSludge => Unit::thick_sludge(position),
            UnitType::Warrior => Unit::warrior(position),
            UnitType::Wizard => Unit::wizard(position),
        }
    }
    
    pub fn archer(position: (i32, i32)) -> Unit {
        Unit {
            unit_type: UnitType::Archer,
            position,
            hp: (7, 7),
            atk: 3,
            facing: None,
        }
    }
    
    pub fn captive(position: (i32, i32)) -> Unit {
        Unit {
            unit_type: UnitType::Captive,
            position,
            hp: (1, 1),
            atk: 0,
            facing: None,
        }
    }
    
    pub fn sludge(position: (i32, i32)) -> Unit {
        Unit {
            unit_type: UnitType::Sludge,
            position,
            hp: (12, 12),
            atk: 3,
            facing: None,
        }
    }
    
    pub fn thick_sludge(position: (i32, i32)) -> Unit {
        Unit {
            unit_type: UnitType::ThickSludge,
            position,
            hp: (18, 18),
            atk: 3,
            facing: None,
        }
    }
    
    pub fn warrior(position: (i32, i32)) -> Unit {
        Unit {
            unit_type: UnitType::Warrior,
            position,
            hp: (20, 20),
            atk: 5,
            facing: Some(Direction::Forward),
        }
    }
    
    pub fn wizard(position: (i32, i32)) -> Unit {
        Unit {
            unit_type: UnitType::Wizard,
            position,
            hp: (3, 3),
            atk: 11,
            facing: None,
        }
    }
}