-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.cc
135 lines (114 loc) · 4.21 KB
/
player.cc
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// player.cc
// Defines the win condition and keeps track of special abilities each player has
//
#include "player.h"
#include "link.h"
#include "graphicsdisplay.h"
#include <string>
#include <iostream>
using namespace std;
Player::~Player(){
}
Player::Player(int pnum, string the_abilities): pnum{pnum}, virus{0}, data{0}{
for(const char &ability: the_abilities){
Ability ab;
if (ability == 'L') ab = Ability::LinkBoost;
else if (ability == 'F') ab = Ability::Firewall;
else if (ability == 'D') ab = Ability::Download;
else if (ability == 'S') ab = Ability::Scan;
else if (ability == 'P') ab = Ability::Polarize;
else if (ability == 'B') ab = Ability::Battle;
else if (ability == 'T') ab = Ability::Trade;
else if (ability == 'N') ab = Ability::Next;
abilities.push_back(make_pair(ab, 1));
}
}
void Player::download(Link* link){
if (link->getState().type == LinkType::Virus) virus++;
else if (link->getState().type == LinkType::Data) data++;
link->remove();
}
Ability Player::getAbility(int n){
if (abilities.at(n).second == 1) return abilities.at(n).first;
else return Ability::No;
}
void Player::removeAb(int n){
abilities.at(n).second = 0;
}
void Player::displayAbilities(){
cout << "Abilities: \n";
for(int i = 0; i < 5; i++){
Ability ability = abilities.at(i).first;
char cur_ab;
if(ability == Ability::LinkBoost) cur_ab = 'L';
else if(ability == Ability::Firewall) cur_ab = 'F';
else if(ability == Ability::Download) cur_ab = 'D';
else if(ability == Ability::Scan) cur_ab = 'S';
else if(ability == Ability::Polarize) cur_ab = 'P';
else if(ability == Ability::Battle) cur_ab = 'B';
else if(ability == Ability::Next) cur_ab = 'N';
else if(ability == Ability::Trade) cur_ab = 'T';
else cur_ab = ' ';
cout << cur_ab << "(" << i + 1 << ") ";
if (abilities.at(i).second == 0) cout << ": Used ";
}
cout << endl;
}
void Player::drawInfo(GraphicsDisplay *gd, int num){
if (this->pnum == num + 1){
gd->drawStr(30, 600, "All Abilities:");
int x = 30;
for(int i = 0; i < 5; i++){
Ability ability = abilities.at(i).first;
string cur_ab;
if(ability == Ability::LinkBoost) cur_ab = "L";
else if(ability == Ability::Firewall) cur_ab = "F";
else if(ability == Ability::Download) cur_ab = "D";
else if(ability == Ability::Scan) cur_ab = "S";
else if(ability == Ability::Polarize) cur_ab = "P";
else if(ability == Ability::Battle) cur_ab = "B";
else if(ability == Ability::Next) cur_ab = "N";
else if(ability == Ability::Trade) cur_ab = "T";
else cur_ab = " ";
if (abilities.at(i).second == 0)
gd->drawStr(x, 620, cur_ab + "(" + to_string(i + 1) + ") " + ": Used ");
else gd->drawStr(x, 620, cur_ab + "(" + to_string(i + 1) + ") ");
x+=65;
}
}
int count = 0;
for (auto i: abilities){
if (i.second == 1) count ++;
}
if (pnum == 1){
gd->drawStr(30, 30, "Player" + to_string(pnum) + ":");
gd->drawStr(30, 50, "Downloaded: " + to_string(data) + "D, " + to_string(virus) + "V");
gd->drawStr(30, 70, "Abilities: " + to_string(count));
} else {
gd->drawStr(30, 530, "Player" + to_string(pnum) + ":");
gd->drawStr(30, 550, "Downloaded: " + to_string(data) + "D, " + to_string(virus) + "V");
gd->drawStr(30, 570, "Abilities: " + to_string(count));
}
}
int Player::winner(){
if (pnum == 1){
if (virus >= 4) return 2;
if (data >= 4) return 1;
else return 0;
} else {
if (virus >= 4) return 1;
if (data >= 4) return 2;
else return 0;
}
}
std::ostream &operator<<(std::ostream &out, const Player &p){
int count = 0;
for (auto i: p.abilities){
if (i.second == 1) count ++;
}
out << "Player " << p.pnum << ":\n";
out << "Downloaded: " << p.data << "D, " << p.virus << "V\n";
out << "Abilities: " << count << "\n";
return out;
}