-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVotingMgr.cpp
More file actions
45 lines (44 loc) · 1.56 KB
/
VotingMgr.cpp
File metadata and controls
45 lines (44 loc) · 1.56 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
#include "VotingMgr.h"
VotingMgr::VotingMgr() {
players.clear();
}
std::vector<int> VotingMgr::GetHighestVoteIds(std::vector<int> &highs, std::vector<int> &second_highss) {
//Find Max
int mx = -1;
for (register int i = 0; i < players.size(); i++) {
if (players[i].second > mx)
mx = players[i].second;
}
int second_mx = -1;
for (register int i = 0; i < players.size(); i++) {
if (players[i].second > second_mx && players[i].second < mx)
second_mx = players[i].second;
}
for (register int i = 0; i < players.size(); i++) {
if (players[i].second == mx)
highs.push_back(players[i].first);
else if (players[i].second == second_mx)
second_highss.push_back(players[i].first);
}
}
void VotingMgr::Vote(God &gd) {
for (register int i = 0; i < gd.GetNoOfPlayers(); i++) {
std::pair<int, int> this_pair(gd.GetPlayerByIndex(i)->GetId(), 0);
players.push_back(this_pair);
}
for (register int i = 0; i < gd.GetNoOfPlayers(); i++) {
Player *tmp = gd.GetPlayerByIndex(i);
if (tmp->GetAlive()) {
std::cout<<"Enter your vote by player name\n";
std::string this_vote;
std::cin>>this_vote;
players[gd.GetIdByPlayerName(this_vote) - 1].second++;
} else {
players[i].second = -1;
}
}
std::vector<int> highest_votes, second_ht_votes;
GetHighestVoteIds(highest_votes, second_ht_votes);
gd.SetHighestVotes(highest_votes);
gd.SetSecondHtVotes(second_ht_votes);
}