-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGod.cpp
More file actions
70 lines (69 loc) · 1.96 KB
/
God.cpp
File metadata and controls
70 lines (69 loc) · 1.96 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
#include "God.h"
#include <iostream>
God::God(int game_ID):game_id(game_ID), Player(0, "God", GOD) {
is_day = true;
mafia_ct = 3;
citizen_ct = 3;
no_of_players = 9;
players.clear();
highest_votes.clear();
second_highest_votes.clear();
}
God::God(const God &cpy):game_id(cpy.GetGameId()), Player(cpy.GetId(), cpy.GetName(), cpy.GetType()) {
for (register int i = 0; i < cpy.GetNoOfPlayers(); i++) {
Player *pl = new Player(*(cpy.GetPlayerByIndex(i)));
players.push_back(pl);
}
}
God::~God() {
for (register int i = 0; i < no_of_players; i++)
delete players[i];
}
void God::Kill(int id) {
Player *tmp_pl = GetPlayerById(id);
tmp_pl->SetAlive(false);
}
void God::Heal(int id) {
Player *tmp_pl = GetPlayerById(id);
tmp_pl->SetAlive(true);
}
Player *God::GetPlayerById(int id) {
for (register int i = 0; i < no_of_players; i++) {
Player *t_pl = GetPlayerByIndex(i);
if (t_pl->GetId() == id)
return t_pl;
}
return NULL;
}
int God::GetIdByPlayerName(std::string name) {
for (register int i = 0; i < no_of_players; i++) {
Player *t_pl = GetPlayerByIndex(i);
if (t_pl->GetName() == name) {
return t_pl->GetId();
}
}
return -1;
}
void God::GetMafiasByIds(std::vector<int> &mafias) {
for (register int i = 0; i < no_of_players; i++) {
Player *tmp = players[i];
if (tmp->GetType() == MAFIA && tmp->GetAlive())
mafias.push_back(tmp->GetId());
}
}
int God::GetHealerById() {
for (register int i = 0; i < no_of_players; i++) {
Player *tmp = players[i];
if (tmp->GetType() == HEALER && tmp->GetAlive())
return tmp->GetId();
}
return -1;
}
int God::GetDetectiveById() {
for (register int i = 0; i < no_of_players; i++) {
Player *tmp = players[i];
if (tmp->GetType() == DETECTIVE && tmp->GetAlive())
return tmp->GetId();
}
return -1;
}