Line |
Branch |
Exec |
Source |
1 |
|
|
#include "Data.hpp" |
2 |
|
|
#include "../utils/GuiException.hpp" |
3 |
|
|
|
4 |
|
|
#include <memory> |
5 |
|
|
#include <utility> |
6 |
|
|
|
7 |
|
|
// ------------------------------------------------------------------ // |
8 |
|
|
// ---------------------------- GETTERS ----------------------------- // |
9 |
|
|
// ------------------------------------------------------------------ // |
10 |
|
|
|
11 |
|
4 |
Egg &Data::getEggById(int eggid) { |
12 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 |
if (this->eggs.find(eggid) == this->eggs.end()) |
13 |
2/4
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
3 |
throw guiException("getEggById: Invalid egg id(" + std::to_string(eggid) + ")"); |
14 |
|
3 |
return this->eggs.at(eggid); |
15 |
|
|
}; |
16 |
|
|
|
17 |
|
2 |
std::string Data::getTeamByName(std::string name) |
18 |
|
|
{ |
19 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 |
for (std::string &team : this->teamNames) { |
20 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
if (team.compare(name) == 0) |
21 |
|
1 |
return team; |
22 |
|
|
} |
23 |
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
3 |
throw guiException("getTeamByName: Invalid team name(" + name + ")"); |
24 |
|
|
}; |
25 |
|
|
|
26 |
|
23 |
std::shared_ptr<Player> Data::getPlayerById(int id) |
27 |
|
|
{ |
28 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 22 times.
|
23 |
if (this->players.find(id) == this->players.end()) |
29 |
2/4
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
3 |
throw guiException("getPlayerById: Invalid player id(" + std::to_string(id) + ")"); |
30 |
|
44 |
return this->players.at(id); |
31 |
|
|
}; |
32 |
|
|
|
33 |
|
5 |
std::shared_ptr<Incantation> Data::getIncantationByPos(std::vector<int> pos) |
34 |
|
|
{ |
35 |
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
|
6 |
for (std::shared_ptr<Incantation> &incantation : this->incantations) { |
36 |
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
|
5 |
if (incantation->getPosition() == pos) |
37 |
|
4 |
return incantation; |
38 |
|
|
} |
39 |
3/6
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
|
4 |
throw guiException("getIncantationByPos: Invalid position(" + std::to_string(pos[0]) + ", " + std::to_string(pos[1]) + ")"); |
40 |
|
|
}; |
41 |
|
|
|
42 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 |
std::optional<Broadcast> Data::getNextBroadcast() { |
43 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 |
if (this->broadcasts.size() <= 0) |
44 |
|
1 |
return std::nullopt; |
45 |
|
2 |
Broadcast b = this->broadcasts.back(); |
46 |
|
2 |
this->broadcasts.pop_back(); |
47 |
|
|
return b; |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
// ------------------------------------------------------------------ // |
51 |
|
|
// ---------------------------- SETTERS ----------------------------- // |
52 |
|
|
// ------------------------------------------------------------------ // |
53 |
|
|
|
54 |
|
|
|
55 |
|
20 |
void Data::addPlayer(std::vector<int> values, std::string teamName) |
56 |
|
|
{ |
57 |
|
20 |
std::vector<int> pos = {values[1], values[2]}; |
58 |
|
20 |
std::shared_ptr<Player> player = std::make_shared<Player>( |
59 |
|
20 |
values[0], |
60 |
|
|
pos, |
61 |
|
20 |
values[3], |
62 |
|
20 |
values[4], |
63 |
|
|
teamName |
64 |
|
|
); |
65 |
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
20 |
players.insert( |
66 |
1/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
20 |
std::pair<int, std::shared_ptr<Player>>( |
67 |
|
20 |
values[0], |
68 |
|
|
player |
69 |
|
|
) |
70 |
|
|
); |
71 |
|
20 |
}; |
72 |
|
|
|
73 |
|
|
|
74 |
|
6 |
void Data::addEgg(std::vector<int> pos, int eggId, int playerId, EggStatus state) |
75 |
|
|
{ |
76 |
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 |
this->eggs.insert( |
77 |
|
6 |
std::make_pair( |
78 |
|
|
eggId, |
79 |
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 |
Egg(pos, eggId, playerId, state) |
80 |
|
|
) |
81 |
|
|
); |
82 |
|
6 |
}; |
83 |
|
|
|
84 |
|
5 |
void Data::addIncantation(std::vector<int> pos, int lvl, std::vector<int> playersId) |
85 |
|
|
{ |
86 |
|
5 |
std::shared_ptr<Incantation> incantation = std::make_shared<Incantation>( |
87 |
|
|
pos, |
88 |
|
|
lvl, |
89 |
|
|
playersId |
90 |
|
|
); |
91 |
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 |
this->incantations.push_back(incantation); |
92 |
|
5 |
}; |
93 |
|
|
|
94 |
|
3 |
void Data::addBroadcast(int playerNb, std::vector<int> pos, std::string msg) |
95 |
|
|
{ |
96 |
|
3 |
this->broadcasts.push_back( |
97 |
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
|
6 |
Broadcast( |
98 |
|
|
playerNb, |
99 |
|
|
msg, |
100 |
|
|
pos |
101 |
|
|
) |
102 |
|
|
); |
103 |
|
3 |
}; |
104 |
|
|
|
105 |
|
|
// ------------------------------------------------------------------ // |
106 |
|
|
// ---------------------------- BOOLEAN ----------------------------- // |
107 |
|
|
// ------------------------------------------------------------------ // |
108 |
|
|
|
109 |
|
3 |
bool Data::doesTeamExist(std::string name) |
110 |
|
|
{ |
111 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 |
for (std::string &team : this->teamNames) { |
112 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
if (team.compare(name) == 0) |
113 |
|
|
return true; |
114 |
|
|
} |
115 |
|
|
return false; |
116 |
|
|
}; |
117 |
|
|
|
118 |
|
|
|
119 |
|
2 |
bool Data::playerExists(int id) |
120 |
|
|
{ |
121 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
if (this->players.find(id) == this->players.end()) |
122 |
|
1 |
return false; |
123 |
|
|
return true; |
124 |
|
|
}; |
125 |
|
|
|
126 |
|
|
// ------------------------------------------------------------------ // |
127 |
|
|
// ---------------------------- RESET ------------------------------ // |
128 |
|
|
// ------------------------------------------------------------------ // |
129 |
|
|
|
130 |
|
✗ |
void Data::resetGame() |
131 |
|
|
{ |
132 |
|
|
this->eggs.clear(); |
133 |
|
|
this->players.clear(); |
134 |
|
✗ |
this->incantations.clear(); |
135 |
|
✗ |
this->broadcasts.clear(); |
136 |
|
|
this->winner = std::nullopt; |
137 |
|
✗ |
this->teamNames.clear(); |
138 |
|
✗ |
this->map.resetMap(); |
139 |
|
✗ |
this->tickRate = 100; |
140 |
|
✗ |
}; |
141 |
|
|
|