-
Notifications
You must be signed in to change notification settings - Fork 0
/
workersclan.cpp
63 lines (55 loc) · 1.81 KB
/
workersclan.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
#include "workersclan.h"
#include "worker.h"
#include "game.h"
extern Game* game;
WorkersClan::WorkersClan(int n, Tent* tent) {
// initialize the vectors
isAlive.resize(n);
for(size_t i = 0; i < isAlive.size(); i++) isAlive[i] = true;
workers.resize(n);
for(size_t i = 0; i < workers.size(); i++) workers[i] = NULL;
// initialize data members
isAvailable = true;
isAllClanDead = false;
this->tent = tent;
numKilled = 0;
}
void WorkersClan::createWorkers(int x, int y) {
setDetX(x);
setDetY(y);
for(size_t i = 0; i < isAlive.size(); i++) {
if(isAlive[i]) {
// qDebug() << "In createWorkers, isAlive[i] = " << isAlive[i] << '\n';
if(isAlive[i] && workers[i] == NULL) {
Worker* w = new Worker(this, i);
workers[i] = w;
game->getScene()->addItem(w);
if(i != isAlive.size() - 1) game->delay(2);
} // else {
// workers[i]->setDetX(x);
// workers[i]->setDetY(y);
// }
}
}
}
bool WorkersClan::getAvailability() {return isAvailable;}
void WorkersClan::changeAvailability(bool b) {
isAvailable = b;
}
void WorkersClan::changeIsAlive(int i) {
isAlive[i] = false;
// qDebug() << "In changeIsAlive, isAlive[i] = " << isAlive[i] << '\n';
numKilled++;
changeWorkerPointerToNULL(i);
if(numKilled == workers.size()) {changeAvailability(false); isAllClanDead = true;}
}
void WorkersClan::changeWorkerPointerToNULL(int i)
{
workers[i] = NULL;
}
Tent* WorkersClan::getTent() {return tent;}
bool WorkersClan::getIsAllClanDead() {return isAllClanDead;}
int WorkersClan::getDetX() {return detX;}
int WorkersClan::getDetY() {return detY;}
void WorkersClan::setDetX(int x) {detX = x;}
void WorkersClan::setDetY(int y) {detY = y;}