-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameState.cpp
More file actions
79 lines (73 loc) · 2.34 KB
/
GameState.cpp
File metadata and controls
79 lines (73 loc) · 2.34 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
#include "GameState.hpp"
#include <string>
using std::string;
void GameState::AddPiece(
string const& person,
string const& figure) { // Appends a new GamePiece to its respective map
if (figure == "Warrior") {
Warriors[person]++;
} else if (figure == "Wizard") {
++Wizards[person];
} else {
Scouts[person]++;
}
}
int GameState::NumPieces() { // Returns the total number of pieces in play in
// the game
int sum = 0;
for (auto i : Warriors) {
sum += i.second;
}
for (auto j : Wizards) {
sum += j.second;
}
for (auto k : Scouts) {
sum += k.second;
}
return sum;
}
int GameState::NumPieces(string const& player_name) { // Returns the total
// number of pieces a
// player owns in the
// game
return Warriors[player_name] + Wizards[player_name] + Scouts[player_name];
}
int GameState::NumPieces(string const& player_name,
string const& piece_type) { // Returns the number of
// pieces a player owns
// that is of a specified
// type
if (piece_type == "Warrior") {
return Warriors[player_name];
} else if (piece_type == "Wizard") {
return Wizards[player_name];
} else if (piece_type == "Scout") {
return Scouts[player_name];
} else {
return 0;
}
}
int GameState::WizardCount(
string const& player) { // Returns the total number of Wizards in play, not
// including the amount owned by a specified player
int WizCo = 0; // Wizard Count
for (auto i : Wizards) {
if (i.first == player) {
continue;
}
WizCo += i.second;
}
return WizCo;
}
void GameState::KillPiece(string const& person,
string const& figure) { // Removes a piece from its
// respective owner by
// decrementing its map value
if (figure == "Warrior") {
Warriors[person]--;
} else if (figure == "Wizard") {
Wizards[person]--;
} else {
Scouts[person]--;
}
}