-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScorecard.cpp
More file actions
126 lines (116 loc) · 3.41 KB
/
Scorecard.cpp
File metadata and controls
126 lines (116 loc) · 3.41 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*********************************************************************
** Author: Melody Reebs
** Date: 06/08/2018
** Title: Yahtzee
** Description: Scorecard class implementation file
*********************************************************************/
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include "Scorecard.hpp"
using std::cout;
using std::endl;
using std::vector;
using std::string;
using std::setw;
using std::left;
// Default constructor
Scorecard::Scorecard() {
numPlayers = 0;
}
// Add player to game
void Scorecard::addPlayer(Player *playerPtr) {
players.push_back(playerPtr);
numPlayers++;
}
// Print the current scorecard
void Scorecard::print() {
// Create separation line strings
int firstCol = 15;
string line, totLine, col;
line.assign(numPlayers * 6 + firstCol + 2, '-');
totLine.assign(numPlayers * 6 + firstCol + 2, '=');
col = " | ";
// Print scorecard header with player names
cout << left << "Yahtzee scorecard" << endl;
cout << totLine << endl;
cout << setw(firstCol) << "Players";
for (int i = 0; i < numPlayers; i++) {
cout << col << players[i]->getInitials();
}
cout << endl;
cout << line << endl;
// Print upper section scores
string upperLabels[] = {" 1. Aces", " 2. Twos", " 3. Threes", " 4. Fours", " 5. Fives", " 6. Sixes"};
cout << "UPPER SECTION" << endl;
cout << line << endl;
for (int j = 0; j < 6; j++) {
cout << setw(firstCol) << upperLabels[j];
for (int i = 0; i < numPlayers; i++) {
int score = players[i]->getUpperScore(j);
cout << col;
if (score > 0) {
cout << setw(3) << score;
}
else if (score == 0) {
cout << setw(3) << "X";
}
else {
cout << setw(3) << "-";
}
}
cout << endl;
}
cout << line << endl;
// Print upper section subtotal and total
cout << setw(firstCol) << "Subtotal";
for (int i = 0; i < numPlayers; i++) {
cout << col << setw(3) << players[i]->getUpperSubTotal();
}
cout << endl;
cout << setw(firstCol) << "Upper Total";
for (int i = 0; i < numPlayers; i++) {
cout << col << setw(3) << players[i]->getUpperTotal();
}
cout << endl << line << endl;
// Print lower section scores
string lowerLabels[] = {" 7. 3 of a Kind", " 8. 4 of a Kind", " 9. Full House", "10. 4 in a Row", "11. 5 in a Row", "12. Yahtzee", "13. Chance"};
cout << "LOWER SECTION" << endl;
cout << line << endl;
for (int j = 0; j < 7; j++) {
cout << setw(firstCol) << lowerLabels[j];
for (int i = 0; i < numPlayers; i++) {
int score = players[i]->getLowerScore(j);
cout << col;
if (score > 0) {
cout << setw(3) << score;
}
else if (score == 0) {
cout << setw(3) << "X";
}
else {
cout << setw(3) << "-";
}
}
cout << endl;
}
cout << line << endl;
// Print lower section subtotal and total
cout << setw(firstCol) << "Subtotal";
for (int i = 0; i < numPlayers; i++) {
cout << col << setw(3) << players[i]->getLowerSubTotal();
}
cout << endl;
cout << setw(firstCol) << "Lower Total";
for (int i = 0; i < numPlayers; i++) {
cout << col << setw(3) << players[i]->getLowerTotal();
}
// Print grand total
cout << endl << totLine << endl;
cout << setw(firstCol) << "GRAND TOTAL";
for (int i = 0; i < numPlayers; i++) {
cout << col << setw(3) << players[i]->getTotalScore();
}
cout << endl << totLine << endl;
}