-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cpp
More file actions
112 lines (97 loc) · 2.04 KB
/
Player.cpp
File metadata and controls
112 lines (97 loc) · 2.04 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
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
/*********************************************************************
** Author: Melody Reebs
** Date: 06/08/2018
** Title: Yahtzee
** Description: Player class implementation file
*********************************************************************/
#include <string>
#include "Player.hpp"
using std::string;
Player::Player(string nm = "Player") {
name = nm;
yahtzeeBonus = 0;
for (int i = 0; i < 6; i++) {
upperScores[i] = -1;
}
for (int i = 0; i < 7; i++) {
lowerScores[i] = -1;
}
}
void Player::setName(string nm) {
name = nm;
}
bool Player::setScore(int category, int val) {
if (category < 7) {
if (upperScores[category - 1] < 0) {
upperScores[category - 1] = val;
return true;
}
else {
return false;
}
}
else {
if (lowerScores[category - 7] < 0) {
lowerScores[category - 7] = val;
return true;
}
else if (category == 12 && lowerScores[category - 7] > 0 && val > 0) {
yahtzeeBonus++;
}
else {
return false; }
}
}
string Player::getName() {
return name;
}
string Player::getInitials() {
return name.substr(0, 3);
}
int Player::getScore(int category) {
if (category < 7) {
return upperScores[category - 1];
}
else {
return lowerScores[category - 7];
}
}
int Player::getUpperScore(int index) {
return upperScores[index];
}
int Player::getLowerScore(int index) {
return lowerScores[index];
}
int Player::getUpperSubTotal() {
int sum = 0;
for (int i = 0; i < 6; i++) {
if (upperScores[i] > 0) {
sum += upperScores[i];
}
}
return sum;
}
int Player::getUpperTotal() {
int subTotal = getUpperSubTotal();
if (subTotal >= 63) {
return subTotal + 35;
}
else {
return subTotal;
}
}
int Player::getLowerSubTotal() {
int sum = 0;
for (int i = 0; i < 7; i++) {
if (lowerScores[i] > 0) {
sum += lowerScores[i];
}
}
return sum;
}
int Player::getLowerTotal() {
return getLowerSubTotal() + (yahtzeeBonus * 100);
}
int Player::getTotalScore() {
return getUpperTotal() + getLowerTotal();
}