-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHuman.cpp
132 lines (119 loc) · 3.09 KB
/
Human.cpp
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
129
130
131
132
#include "Human.h"
#include "Button.h"
#define BOOST_TIME 5
Human::Human(Organisms* organisms, Coordinates coordinates) {
boostIsAvaliable = true;
boostIsActive = false;
isAlive = true;
turnsToBoost = 0;
boostTurns = 0;
features.strength = 5;
features.initiative = 4;
features.age = 0;
features.sign = 'H';
features.name = "Czlowiek";
world = organisms;
this->coordinates = coordinates;
}
/*Metoda obslugujaca akcje wykonywana przez czlowieka - ruch strzalkami oraz aktywowanie umiejetnosci specjalnej - spacja*/
void Human::action(int btn){
boostLoading();
int dx = 0, dy = 0;
switch (btn) {
case KEY_UP:
dy = -1;
break;
case KEY_DOWN:
dy = 1;
break;
case KEY_RIGHT:
dx = 1;
break;
case KEY_LEFT:
dx = -1;
break;
case KEY_SPACE:
boostActivating();
break;
}
Coordinates newCoordinates = this->coordinates.move(dx, dy);
Organism* adjacentOrganism = world->getOrganism(newCoordinates);
if (!boostIsActive) {
if (adjacentOrganism != nullptr && adjacentOrganism != this) {
collision(adjacentOrganism);
}
else {
this->takeMove(newCoordinates);
}
}
else {
boostManagement(newCoordinates);
}
}
/*Metoda aktywowania umiejetnosci specjalnej*/
void Human::boostActivating(){
if (boostIsAvaliable) {
boostIsAvaliable = false;
boostIsActive = true;
string report = "Umiejentosc Calopaenia zostala aktywowana przez czlowieka";
world->addReport(report);
}
else {
string report = "Umiejentosc Calopaenia nie jest aktualnie dostepna, badz jest juz aktywna";
world->addReport(report);
}
}
/*Metoda laduje umiejetnosc specjalna czlowieka*/
void Human::boostLoading() {
if (turnsToBoost > 0 && !boostIsActive) {
--turnsToBoost;
}
else if (turnsToBoost == 0 && !boostIsActive) {
boostIsAvaliable = true;
}
}
/*Metoda wykonujaca specjalna umiejetnosc przez czlowieka - calopalenie, trwa 5 rund i niszczy wszystkie organizmy wokol*/
void Human::boostManagement(Coordinates coordinates){
if (boostTurns < BOOST_TIME) {
this->takeMove(coordinates);
Coordinates currCoordinations;
Organism* organismAround;
for (int i = -1; i < 2; i++) {
for (int j = -1; j < 2; j++) {
currCoordinations = coordinates.move(i, j);
organismAround = world->getOrganism(currCoordinations);
if (organismAround != nullptr && organismAround != this) {
world->addTokillOrganism(organismAround->getCoordinates());
world->removeField(organismAround->getCoordinates());
string report = "Umiejentosc Calopaenia zneutralizowala " + organismAround->getName();
world->addReport(report);
}
}
}
++boostTurns;
}
else {
boostIsActive = false;
boostIsAvaliable = false;
turnsToBoost = 5;
boostTurns = 0;
}
}
int Human::getTurnsToBoost() const{
return this->turnsToBoost;
}
int Human::getBoostTurns() const{
return this->boostTurns;
}
void Human::setTurnsToBoost(int turnsToBoost){
this->turnsToBoost = turnsToBoost;
}
void Human::setBoostTurns(int boostTurns){
this->boostTurns = boostTurns;
}
void Human::setBoostIsActive(bool option){
this->boostIsActive = option;
}
void Human::setBoostIsAvaliable(bool option){
this->boostIsAvaliable = option;
}