Christian пре 9 година
родитељ
комит
60c1c9cd28
4 измењених фајлова са 508 додато и 0 уклоњено
  1. 243
    0
      BPlayer.cpp
  2. 47
    0
      BPlayer.h
  3. 208
    0
      BPlayerClient.cpp
  4. 10
    0
      makefile

+ 243
- 0
BPlayer.cpp Прегледај датотеку

@@ -0,0 +1,243 @@
1
+#include "BPlayer.h"
2
+#include <iostream>
3
+#include <stdio.h>      
4
+#include <stdlib.h>     
5
+#include <time.h>    
6
+
7
+using namespace std;
8
+
9
+
10
+/*====================================
11
+			Constructor
12
+====================================*/
13
+BPlayer::BPlayer() {
14
+	srand(time(NULL));
15
+	Number = rand() % 51;
16
+	FG = FGattempt = FGPercentage = Thrpt = Thrptattempt = ThrptPercentage = 
17
+	FT = FTattempt = FTPercentage = Points = Rebs = Asts = Stls = Blocks = 
18
+	Fouls = Turnovers = 0;
19
+}
20
+
21
+BPlayer::BPlayer(unsigned short number) {
22
+	Number = number;
23
+	FG = FGattempt = FGPercentage = Thrpt = Thrptattempt = ThrptPercentage = 
24
+	FT = FTattempt = FTPercentage = Points = Rebs = Asts = Stls = Blocks = 
25
+	Fouls = Turnovers = 0;
26
+}
27
+
28
+
29
+/*====================================
30
+				Adders
31
+====================================*/
32
+
33
+void BPlayer::shotTaken() {
34
+	int option;
35
+	cout << "FG Made (1) FG Missed (2) 3pt Made (3) 3pt Missed (4)\n"
36
+		 << "FT Made (5) FT Missed (6) None (7)\n";
37
+	cin >> option;
38
+	
39
+	if(option == 1){
40
+		FG++;
41
+		FGattempt++;
42
+		Points += 2;
43
+	}
44
+	else if(option == 2){
45
+		FGattempt++;
46
+	}
47
+	else if(option == 3){
48
+		Thrpt++;
49
+		Thrptattempt++;
50
+		Points += 3;
51
+	}
52
+	else if(option == 4){
53
+		Thrptattempt++;
54
+	}
55
+	else if(option == 5){
56
+		FT++;
57
+		FTattempt++;
58
+		Points++;
59
+	}
60
+	else if(option == 6){
61
+		FTattempt++;
62
+	}
63
+	else{
64
+		return;
65
+	}
66
+}
67
+
68
+void BPlayer::addReb() { Rebs++; }
69
+
70
+void BPlayer::addAst() { Asts++; }
71
+
72
+void BPlayer::addStl() { Stls++; }
73
+
74
+void BPlayer::addBlock() { Blocks++; }
75
+
76
+void BPlayer::addFoul() { Fouls++; }
77
+
78
+void BPlayer::addTurnover() { Turnovers++; }
79
+
80
+
81
+/*===================================
82
+			Subtractors
83
+===================================*/
84
+
85
+/*****************************************************
86
+Remover los ifs que validan si ya estan en 0 los stats
87
+*****************************************************/
88
+
89
+void BPlayer::remPoints() {
90
+	int option;
91
+	cout << "Remove FG (1) Remove 3pt (2) Remove FT (3) None (4)\n";
92
+	cin >> option;
93
+	
94
+	if(Points == 0) {
95
+		cout << "The player doesn't have any points to remove\n\n";
96
+	}
97
+	 if(option == 1){
98
+		FG--;
99
+		FGattempt--;
100
+		Points -= 2;
101
+	}
102
+	else if(option == 2){
103
+		Thrpt--;
104
+		Thrptattempt--;
105
+		Points -= 3;
106
+	}
107
+	else if(option == 3){
108
+		FT--;
109
+		FTattempt--;
110
+		Points--;
111
+	}
112
+	else {
113
+		return;
114
+	}
115
+}
116
+
117
+void BPlayer::remReb() { 
118
+	if(Rebs == 0) {
119
+		cout << "The player doesn't have any rebounds to remove\n\n";
120
+	}
121
+	else {
122
+		Rebs--;
123
+	} 
124
+}
125
+
126
+void BPlayer::remAst() { 
127
+	if(Asts == 0) {
128
+		cout << "The player doesn't have any assists to remove\n\n";
129
+	}
130
+	else {
131
+		Asts--; 
132
+	}
133
+}
134
+
135
+void BPlayer::remStl() { 
136
+	if(Stls == 0) {
137
+		cout << "The player doesn't have any steals to remove\n\n";
138
+	}
139
+	else {
140
+		Stls--; 
141
+	}
142
+}
143
+
144
+void BPlayer::remBlock() { 
145
+	if(Blocks == 0) {
146
+		cout << "The player doesn't have any blocks to remove\n\n";
147
+	}
148
+	else {
149
+		Blocks--; 
150
+	}
151
+}
152
+
153
+void BPlayer::remFoul() { 
154
+	if(Fouls == 0) {
155
+		cout << "The player doesn't have any fouls to remove\n\n";
156
+	}
157
+	else {
158
+		Fouls--; 
159
+	}
160
+}
161
+
162
+void BPlayer::remTurnover() { 
163
+	if(Turnovers == 0) {
164
+		cout << "The player doesn't have any turnovers to remove\n\n";
165
+	}
166
+	else {
167
+		Turnovers--; 
168
+	}
169
+}
170
+
171
+
172
+/*==================================================
173
+					Getters
174
+==================================================*/
175
+unsigned short BPlayer::getNumber() const { return Number; }
176
+
177
+unsigned short BPlayer::getPoints() const { return Points; }
178
+
179
+float BPlayer::getFGPercentage() const { 
180
+	if(FG == 0 && FGattempt == 0) { 
181
+		return 0; 
182
+	}
183
+	else { 
184
+		return FG / FGattempt * 100; 
185
+	}
186
+}
187
+
188
+float BPlayer::getThrptPercentage() const { 
189
+	if(Thrpt == 0 && Thrptattempt == 0) { 
190
+		return 0; 
191
+	}
192
+	else { 
193
+		return Thrpt / Thrptattempt * 100; 
194
+	}
195
+}
196
+
197
+float BPlayer::getFTPercentage() const {
198
+	if(FT == 0 && FTattempt == 0) { 
199
+		return 0; 
200
+	}
201
+	else { 
202
+		return FT / FTattempt * 100; 
203
+	}
204
+}
205
+
206
+unsigned short BPlayer::getRebs() const { return Rebs; }
207
+
208
+unsigned short BPlayer::getAsts() const { return Asts; }
209
+
210
+unsigned short BPlayer::getStls() const { return Stls; }
211
+
212
+unsigned short BPlayer::getBlocks() const { return Blocks; }
213
+
214
+unsigned short BPlayer::getFouls() const { return Fouls; }
215
+
216
+unsigned short BPlayer::getTurnovers() const { return Turnovers; }
217
+
218
+
219
+void BPlayer::showStats() {
220
+	cout << "Points\tFG%\tThrpt%\tFT%\tRebounds\n";
221
+	
222
+	for(int i = 0; i < 44; i++) {
223
+		cout << "-";
224
+	}
225
+	
226
+	cout << "\n" << Points << "\t" << getFGPercentage() << "\t"
227
+		 <<  getThrptPercentage() << "\t" << getFTPercentage() << "\t"
228
+		 << Rebs << "\n";
229
+	
230
+	for(int i = 0; i < 44; i++) {
231
+		cout << "=";
232
+	}
233
+
234
+	cout << "\nAssists\tSteals\tBlocks\tFouls\tTurnovers\n";
235
+	
236
+	for(int i = 0; i < 44; i++) {
237
+		cout << "-";
238
+	}
239
+
240
+	cout << "\n" << Asts << "\t" << Stls << "\t"
241
+		 <<  Blocks << "\t" << Fouls << "\t"
242
+		 << Turnovers << "\n";
243
+}

+ 47
- 0
BPlayer.h Прегледај датотеку

@@ -0,0 +1,47 @@
1
+#ifndef PLAYER_H 	
2
+#define PLAYER_H
3
+#include <iostream>
4
+
5
+using namespace std;
6
+
7
+class BPlayer {
8
+private:
9
+	unsigned short Number, Points, Rebs, Asts, Stls, Blocks, Fouls, Turnovers;
10
+	float FGPercentage, ThrptPercentage, FTPercentage, FG, FGattempt, Thrpt, Thrptattempt, FT, FTattempt;
11
+public:
12
+	BPlayer();
13
+	BPlayer(unsigned short number);
14
+
15
+	void shotTaken();
16
+	void addReb();
17
+	void addAst();
18
+	void addStl();
19
+	void addBlock();
20
+	void addFoul();
21
+	void addTurnover();
22
+
23
+	void remPoints();
24
+	void remReb();
25
+	void remAst();
26
+	void remStl();
27
+	void remBlock();
28
+	void remFoul();
29
+	void remTurnover();
30
+
31
+	unsigned short getNumber() const;
32
+	unsigned short getPoints() const;
33
+	float getFGPercentage() const;
34
+	float getThrptPercentage() const;
35
+	float getFTPercentage() const;
36
+	unsigned short getRebs() const;
37
+	unsigned short getAsts() const;
38
+	unsigned short getStls() const;
39
+	unsigned short getBlocks() const;
40
+	unsigned short getFouls() const;
41
+	unsigned short getTurnovers() const;
42
+
43
+	void showStats();
44
+
45
+};
46
+
47
+#endif

+ 208
- 0
BPlayerClient.cpp Прегледај датотеку

@@ -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
+}

+ 10
- 0
makefile Прегледај датотеку

@@ -0,0 +1,10 @@
1
+all: BPlayer
2
+
3
+BPlayer.o: BPlayer.h BPlayer.cpp
4
+	g++ -c BPlayer.cpp
5
+
6
+BPlayer: BPlayer.o BPlayerClient.cpp
7
+	g++ -o client BPlayer.o BPlayerClient.cpp
8
+
9
+clean:
10
+	rm client *.o