-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
38 lines (32 loc) · 884 Bytes
/
Player.cpp
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
//
// Created by riham on 24/10/18.
//
#include "Player.h"
Player::Player(int playerId) : playerId(playerId) {
memset(myTies, 0, sizeof myTies);
}
bool Player::addTie(int tie) {
if (totalTies >= PLAYER_TIES_SIZE) return false;
myTies[tie]++;
totalTies++;
return true;
}
bool Player::playTie(int tie) {
if (myTies[tie] <= 0) return false; // the player doesn't have any ties yet
myTies[tie]--;
totalTies--;
return true;
}
int Player::getTotalTies() {
return totalTies;
}
ostream& operator<<(ostream& os, Player const& myObj) {
os << "\nPlayer: " << myObj.playerId << "\ttotal number of ties: " << myObj.totalTies << "\t ties: ";
for (int i = 0; i < 27; i++) {
if (myObj.myTies[i] != 0) {
os << "( char=" << char(i+'A') << ", count=" << myObj.myTies[i] << " ) ";
}
}
os << endl;
return os;
}