-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzombie.cpp
More file actions
122 lines (89 loc) · 2.53 KB
/
zombie.cpp
File metadata and controls
122 lines (89 loc) · 2.53 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
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
119
120
121
122
#include "zombie.h"
Zombie::Zombie(int H, int d, int atra, bool isr, bool isp, bool isz, bool ifl, QString n, int icost)
: Creature(H, d, atra, isr, isp, isz, ifl, n, icost)
{
}
FlyZ::FlyZ(int H, int d, int atra, QString n, bool isr, bool isp, bool isz, bool ifl)
: Zombie(H, d, atra, isr, isp, isz, ifl, n)
{
}
NormalZombie::NormalZombie(int H, int d, int atra, bool isr, bool isp, bool isz, bool ifl, QString n, int icost)
: Zombie(H, d, atra, isr, isp, isz, ifl, n, icost)
{
setFoot(0.1);
}
RemoteZombie::RemoteZombie(int H, int d, int atra, bool isr, bool isp, bool isz, bool ifl, QString n, int icost)
: Zombie(H, d, atra, isr, isp, isz, ifl, n, icost)
{
}
Ballon::Ballon(int H, int d, int atra, QString n) : FlyZ(H, d, atra, n)
{
setWarlike(false);
setFoot(0.1);
}
bool Zombie::canAttack(Creature *crt) {
bool result = true;
QChar targetDirection = way[0];
float targetx = crt->getCx(), targety = crt->getCy();
if (targetDirection == 'N') {
if (targety == cy && targetx - cx >= 0 && targetx - cx <= 1) {
result = true;
}
else {
result = false;
}
}
else if (targetDirection == 'W') {
if (targetx == cx && cy - targety >= 0 && cy - targety <= 1) {
result = true;
}
else {
result = false;
}
}
else if (targetDirection == 'S') {
if (targety == cy && cx - targetx >= 0 && cx - targetx <= 1) {
result = true;
}
else {
result = false;
}
}
else if (targetDirection == 'E') {
if (targetx == cx && targety - cy >= 0 && targety - cy <= 1) {
result = true;
}
else {
result = false;
}
}
else {
qDebug() << "Wrong Direction!!!";
}
return result;
}
void Zombie::zombieMove() {
QChar a = way[0];
if (a == 'N') {
cx -= foot;
}
else if (a == 'W') {
cy -= foot;
}
else if (a == 'S') {
cx += foot;
}
else if (a == 'E') {
cy += foot;
}
else {
qDebug() << "Wrong Direction!!!";
}
if (abs(cx - round(cx)) < foot/2 && abs(cy - round(cy)) < foot/2) {
//qDebug() << cx << " " << cy;
//qDebug() << "---------------------------------------------------------";
cx = round(cx);
cy = round(cy);
way.remove(0,1);
}
}