-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuman.cpp
More file actions
128 lines (117 loc) · 2.2 KB
/
Human.cpp
File metadata and controls
128 lines (117 loc) · 2.2 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
123
124
125
126
127
128
#include"Human.h"
#include"Animal.h"
#include"World.h"
#include<conio.h>
#include"config.h"
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define ESC 27
Human::Human(int power, int activity, World *world, int x, int y)
:Animal(power, activity, world, x, y)
{
image = 'H';
}
Human::~Human()
{
world->humanDie();
}
void Human::action(int dx, int dy)
{
bool move = false;
int zn = 0;
while (!move)
{
zn = 0;
move = true;
zn = getch();
switch (zn)
{
case UP:
if (skill > 0)
fire(0, -1);
else
Animal::action(0, -1);
break;
case RIGHT:
if (skill > 0)
fire(1, 0);
else
Animal::action(1, 0);
break;
case DOWN:
if (skill > 0)
fire(0, 1);
else
Animal::action(0, 1);
break;
case LEFT:
if (skill > 0)
fire(-1, 0);
else
Animal::action(-1, 0);
break;
case ESC:
world->endGame();
break;
case ' ':
if (skill > 0)
fire();
else if (skill == 0)
{
world->addComment(string(1, image), "actived fire");
skill = SKILL_DURATION;
image = 'O';
fire();
}
else if (skill < 0)
{
world->addComment("Fire light up;", to_string((-1)*skill - 1) + " to ignite");
}
break;
default:
move = false;
}
}
if (skill < 0) skill++;
}
void Human::collistion(Organism * attacker)
{
if (skill > 0)
{
world->delOrganism(attacker);
world->addComment("H", "burn", string(1, attacker->getImage()));
}
else
{
Animal::collision(attacker);
}
}
void Human::fire(int move_x, int move_y)
{
world->addComment("H:", "BURN IT ALL!;", to_string(skill-1)+" left");
if (move_x != 0 || move_y != 0)
{
char place = world->checkPlace(x + move_x, y + move_y);
if(place != ' ' && place != '!')
world->delOrganism(NULL, x + move_x, y + move_y);
Animal::action(move_x, move_y);
}
int dx[] = { MOVE_RANGE_X };
int dy[] = { MOVE_RANGE_Y };
for (int i = 0; i < sizeof(dx) / sizeof(dx[0]); i++)
{
char place = world->checkPlace(x + dx[i], y + dy[i]);
if (place != ' ' && place != '!')
{
world->delOrganism(0, x + dx[i], y + dy[i]);
}
}
if (--skill == 0)
{
skill = -SKILL_DURATION-1;
world->addComment("H:", "Flame went out;", to_string((-1)*skill - 1) + " to ignite");
image = 'H';
}
}