|
@@ -0,0 +1,208 @@
|
|
1
|
+#include "BPlayer.h"
|
|
2
|
+#include <iostream>
|
|
3
|
+#include <vector>
|
|
4
|
+#include <stdio.h>
|
|
5
|
+#include <stdlib.h>
|
|
6
|
+#include <time.h>
|
|
7
|
+using namespace std;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+void options(vector<BPlayer> &team, int &game) {
|
|
11
|
+ int option;
|
|
12
|
+ unsigned short player;
|
|
13
|
+ bool ask = true;
|
|
14
|
+ int index;
|
|
15
|
+
|
|
16
|
+ do{
|
|
17
|
+ cout << "Players: ";
|
|
18
|
+ for(int i = 0; i < team.size(); i++) {
|
|
19
|
+ cout << team[i].getNumber() << " ";
|
|
20
|
+ }
|
|
21
|
+ cout << "\nChoose the player: ";
|
|
22
|
+ cin >> player;
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+ for(int i = 0; i < team.size(); i++) {
|
|
26
|
+ if(player == team[i].getNumber()) {
|
|
27
|
+ index = i;
|
|
28
|
+ ask = false;
|
|
29
|
+ }
|
|
30
|
+ }
|
|
31
|
+ } while(ask);
|
|
32
|
+
|
|
33
|
+//***********************************
|
|
34
|
+
|
|
35
|
+ cout << "====================Menu====================\n";
|
|
36
|
+ cout << "(1) Add shot/points\n";
|
|
37
|
+ cout << "(2) Add rebound\n";
|
|
38
|
+ cout << "(3) Add assist\n";
|
|
39
|
+ cout << "(4) Add steal\n";
|
|
40
|
+ cout << "(5) Add block\n";
|
|
41
|
+ cout << "(6) Add foul\n";
|
|
42
|
+ cout << "(7) Add turnover\n\n";
|
|
43
|
+
|
|
44
|
+ cout << "(8) Remove shot/points\n";
|
|
45
|
+ cout << "(9) Remove rebound\n";
|
|
46
|
+ cout << "(10) Remove assist\n";
|
|
47
|
+ cout << "(11) Remove steal\n";
|
|
48
|
+ cout << "(12) Remove block\n";
|
|
49
|
+ cout << "(13) Remove foul\n";
|
|
50
|
+ cout << "(14) Remove turnover\n\n";
|
|
51
|
+
|
|
52
|
+ cout << "(15) Show stats\n";
|
|
53
|
+ cout << "(16) End game\n";
|
|
54
|
+ cout << "============================================\n\n";
|
|
55
|
+
|
|
56
|
+ cout << "What is your option? ";
|
|
57
|
+ cin >> option;
|
|
58
|
+ cout << "\n";
|
|
59
|
+
|
|
60
|
+ if(option == 1) { team[index].shotTaken();}
|
|
61
|
+ else if(option == 2) { team[index].addReb(); }
|
|
62
|
+ else if(option == 3) { team[index].addAst(); }
|
|
63
|
+ else if(option == 4) { team[index].addStl(); }
|
|
64
|
+ else if(option == 5) { team[index].addBlock(); }
|
|
65
|
+ else if(option == 6) { team[index].addFoul(); }
|
|
66
|
+ else if(option == 7) { team[index].addTurnover(); }
|
|
67
|
+
|
|
68
|
+ else if(option == 8) { team[index].remPoints(); }
|
|
69
|
+ else if(option == 9) { team[index].remReb(); }
|
|
70
|
+ else if(option == 10) { team[index].remAst(); }
|
|
71
|
+ else if(option == 11) { team[index].remStl(); }
|
|
72
|
+ else if(option == 12) { team[index].remBlock(); }
|
|
73
|
+ else if(option == 13) { team[index].remFoul(); }
|
|
74
|
+ else if(option == 14) { team[index].remTurnover(); }
|
|
75
|
+
|
|
76
|
+ else if(option == 15) { team[index].showStats(); }
|
|
77
|
+ else if(option == 16) { game = 0; }
|
|
78
|
+}
|
|
79
|
+
|
|
80
|
+//------------------------------------------------------
|
|
81
|
+unsigned short totalPoints(vector <BPlayer> &team){
|
|
82
|
+ unsigned short total = 0;
|
|
83
|
+ for(int i = 0; i < team.size(); i++){
|
|
84
|
+ total = team[i].getPoints();
|
|
85
|
+ }
|
|
86
|
+ return total;
|
|
87
|
+}
|
|
88
|
+//------------------------------------------------------
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+void displayGameStats(vector<BPlayer> &team1, vector<BPlayer> &team2) {
|
|
92
|
+ for(int i = 0; i < 42; i++) {
|
|
93
|
+ cout << "*";
|
|
94
|
+ }
|
|
95
|
+ cout << "TEAM 1";
|
|
96
|
+ for(int i = 0; i < 42; i++) {
|
|
97
|
+ cout << "*";
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+ cout << "\nPlayer\tPoints\tFG%\tThrpt%\tFT%\tRebs\tAsts\tStls\tBlocks\tFouls\tTurnovers\n";
|
|
102
|
+
|
|
103
|
+ for(int i = 0; i < 90; i++) {
|
|
104
|
+ cout << "-";
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ for(int i = 0; i < team1.size(); i++) {
|
|
108
|
+ cout << "\n" << team1[i].getNumber() << "\t" << team1[i].getPoints() << "\t" << team1[i].getFGPercentage() << "\t" << team1[i].getThrptPercentage()
|
|
109
|
+ << "\t" << team1[i].getFTPercentage() << "\t" << team1[i].getRebs() << "\t" << team1[i].getAsts() << "\t" << team1[i].getStls() << "\t"
|
|
110
|
+ << team1[i].getBlocks() << "\t" << team1[i].getFouls() << "\t" << team1[i].getTurnovers() << "\n\n";
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ for(int i = 0; i < 42; i++) {
|
|
114
|
+ cout << "*";
|
|
115
|
+ }
|
|
116
|
+ cout << "TEAM 2";
|
|
117
|
+ for(int i = 0; i < 42; i++) {
|
|
118
|
+ cout << "*";
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+ cout << "\nPlayer\tPoints\tFG%\tThrpt%\tFT%\tRebs\tAsts\tStls\tBlocks\tFouls\tTurnovers\n";
|
|
123
|
+
|
|
124
|
+ for(int i = 0; i < 90; i++) {
|
|
125
|
+ cout << "-";
|
|
126
|
+ }
|
|
127
|
+
|
|
128
|
+ for(int i = 0; i < team2.size(); i++) {
|
|
129
|
+ cout << "\n" << team2[i].getNumber() << "\t" << team2[i].getPoints() << "\t" << team2[i].getFGPercentage() << "\t" << team2[i].getThrptPercentage()
|
|
130
|
+ << "\t" << team2[i].getFTPercentage() << "\t" << team2[i].getRebs() << "\t" << team2[i].getAsts() << "\t" << team2[i].getStls() << "\t"
|
|
131
|
+ << team2[i].getBlocks() << "\t" << team2[i].getFouls() << "\t" << team2[i].getTurnovers() << "\n\n";
|
|
132
|
+ }
|
|
133
|
+}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+int main() {
|
|
137
|
+ srand(time(NULL));
|
|
138
|
+ vector<BPlayer> team1, team2;
|
|
139
|
+ unsigned short totalTeam1, totalTeam2;
|
|
140
|
+ int players;
|
|
141
|
+
|
|
142
|
+ cout << "How many players are in each team? ";
|
|
143
|
+ cin >> players;
|
|
144
|
+
|
|
145
|
+// Player numbers: Team 1
|
|
146
|
+/********************************************
|
|
147
|
+ Remove code here so that numbers can repeat
|
|
148
|
+*********************************************/
|
|
149
|
+ int count = 0;
|
|
150
|
+ for(int i = 0; i < players; i++) {
|
|
151
|
+ unsigned short number = rand() % 51;
|
|
152
|
+ for(int j = 0; j < count; j++) {
|
|
153
|
+ if(number == team1[i].getNumber()) {
|
|
154
|
+ number = rand() % 51;
|
|
155
|
+ }
|
|
156
|
+ }
|
|
157
|
+ team1.push_back(BPlayer(number));
|
|
158
|
+ }
|
|
159
|
+
|
|
160
|
+// Player numbers: Team 2
|
|
161
|
+/********************************************
|
|
162
|
+ Remove code here so that numbers can repeat
|
|
163
|
+*********************************************/
|
|
164
|
+ count = 0;
|
|
165
|
+ for(int i = 0; i < players; i++) {
|
|
166
|
+ unsigned short number = rand() % 51;
|
|
167
|
+ for(int j = 0; j < count; j++) {
|
|
168
|
+ if(number == team2[i].getNumber()) {
|
|
169
|
+ number = rand() % 51;
|
|
170
|
+ }
|
|
171
|
+ }
|
|
172
|
+ team2.push_back(BPlayer(number));
|
|
173
|
+ }
|
|
174
|
+
|
|
175
|
+ int game = 1;
|
|
176
|
+ while(game) {
|
|
177
|
+ int team;
|
|
178
|
+
|
|
179
|
+ cout << "Choose a team (1 or 2): ";
|
|
180
|
+ cin >> team;
|
|
181
|
+
|
|
182
|
+ if(team == 1){
|
|
183
|
+ options(team1, game);
|
|
184
|
+ }
|
|
185
|
+ else{
|
|
186
|
+ options(team2, game);
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ }
|
|
190
|
+ cout << "The game has ended.\n\n";
|
|
191
|
+
|
|
192
|
+ displayGameStats(team1, team2);
|
|
193
|
+
|
|
194
|
+ totalTeam1 = totalPoints(team1);
|
|
195
|
+ totalTeam2 = totalPoints(team2);
|
|
196
|
+
|
|
197
|
+ if(totalTeam1 > totalTeam2) {
|
|
198
|
+ cout << totalTeam1 << " - " << totalTeam2 << " TEAM 1 HAS WON!\n\n";
|
|
199
|
+ }
|
|
200
|
+ else if(totalTeam1 < totalTeam2) {
|
|
201
|
+ cout << totalTeam1 << " - " << totalTeam2 << " TEAM 2 HAS WON!\n\n";
|
|
202
|
+ }
|
|
203
|
+ else {
|
|
204
|
+ cout << totalTeam1 << " - " << totalTeam2 << " IT'S A TIE!\n\n";
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ return 0;
|
|
208
|
+}
|