-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoldier.cpp
More file actions
87 lines (82 loc) · 1.57 KB
/
Soldier.cpp
File metadata and controls
87 lines (82 loc) · 1.57 KB
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
#include "Game_Object.h"
#include "View.h"
#include "Person.h"
#include "Soldier.h"
//creates a soldier as a person with range and attack_strength variables
Soldier::Soldier() : Person('S')
{
range=2.0;
attack_strength=2;
state='s';
cout<< "default soldier constructed"<< endl;
}
//creates a soldier with an id number, and location
Soldier::Soldier(int id_num, Cart_Point location):Person('S', id_num, location)
{
range=2.0;
attack_strength=2;
state='s';
cout<< "soldier constructed"<< endl;
}
//has the soldier to start attacking if not dead and notifies the status of the attack when updated
void Soldier::start_attack(Person* in_target)
{
if (state=='x')
{
cout<< "Dead can't attack"<< endl;
}
else if (cart_distance((in_target->get_location()), location)<=2)
{
if (in_target->is_alive())
{
cout<< "Clang!"<< endl;
state='a';
in_target-> take_hit(attack_strength);
}
else
{
cout<< "I triumph!"<< endl;
state='s';
}
}
else
{
cout<< "Target is out of range"<< endl;
state='s';
}
}
//updates the soldier class
bool Soldier::update()
{switch (state)
{
case 'x':
{return false;}
case 's':
{return false;}
// moves the soldier
case 'm':
if(update_location()!=true)
{return false;
}
else
{//if the soldier is at the location, stops the miner
state='s';
return true;
}
case 'a':
if (state=='s')
{return true;}
else
{return false;}
}
}
//shows what the soldier is doing
void Soldier::show_status()
{
cout<< "Soldier status:";
Person::show_status();
if (state=='a')
cout<< "Attacking"<< endl;
else
cout<< " is not attacking"<< endl;
}