-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPS.cpp
More file actions
362 lines (305 loc) · 12.4 KB
/
Copy pathRPS.cpp
File metadata and controls
362 lines (305 loc) · 12.4 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#include <iostream>
#include <cstdlib>
#include <string>
#include <thread>
#include <chrono>
using namespace std;
int set_rules();
void Single_Player(int games);
void Two_Player(int games);
void decide_winner(int pOne_Input, int pTwo_Input, int& Score1, int& Score2);
bool check_Input(int RPS_Choice);
int main(){
bool leave_game = false;
int choice = 0;
int games_to_win = 0;
while(leave_game == false){
cout << "Welcome to Rock, Paper, Scissor!" << endl;
cout << "Select your game mode by entering the number below:" << endl << endl;
cout << "\t1) Single Player" << endl << "\t2) 2-Player" << endl << "\t3) Exit";
cout << endl << endl << "Selection: ";
cin >> choice;
//cout << endl << "Your Selection is: " << choice;
system("cls");
switch(choice){
case 1:
cout << "Welcome to Single Player Mode!" << endl;
games_to_win = set_rules();
Single_Player(games_to_win);
break;
case 2:
cout << "Welcome to 2-Player Mode!" << endl;
games_to_win = set_rules();
Two_Player(games_to_win);
break;
case 3:
cout << "Goodbye! Thank you for Playing!" << endl;
leave_game == true;
exit(0);
break;
default:
cout << "Invalid Selection" << endl;
break;
}
this_thread::sleep_for(chrono::seconds(5));
system("cls");
}
cout << "End of Program!";
return 0;
}
int set_rules(){
int games;
do{
cout << "How many games would you like to play?" << endl;
cout << "* This represents shows how many games you are playing the best of. Even numbers will be rounded up. *" << endl;
cout << "Best of: ";
cin >> games;
cout << endl;
if (games <= 0){
cout << "Please enter a positive number of games" << endl;
}
} while (games <= 0);
//Creates odd number of games to win
if (games % 2 == 0 ){
games = games / 2;
games += 1;
}
else{
games += 1;
games = games / 2;
}
return games;
}
/*
The value of 1 represent Rock
The value of 2 represent Paper
The value of 3 represent Scissors
*/
void Single_Player(int games){
int round_num = 1;
int player_score = 0;
int CPU_score = 0;
int pOne_Input = 0;
int CPU_Input;
bool valid_input = false;
system("cls");
while (player_score < games && CPU_score < games){
cout << "Round " << round_num << endl;
cout << "---------------------------" << endl;
cout << "\tScores:" << endl;
cout << "Player 1: " << player_score << endl;
cout << "CPU: " << CPU_score << endl << endl << endl;
do{
cout << "1) Rock" << endl <<
"2) Paper" << endl <<
"3) Scissors" << endl << endl;
cout << "Your turn Player 1! Make a selection from the numbers above." << endl
<< "Selection: ";
cin >> pOne_Input;
cout << endl;
valid_input = check_Input(pOne_Input);
} while(valid_input == false);
CPU_Input = ((rand() % 3) + 1);
system("cls");
decide_winner(pOne_Input, CPU_Input, player_score, CPU_score);
round_num++;
}
cout << endl << "Please wait to continue" << endl;
this_thread::sleep_for(chrono::seconds(2));
system("cls");
if (player_score == games){
cout << "Congrats! You have won the game!" << endl;
}
else{
cout << "You lose! Better luck next time!" << endl << endl;
}
cout << "Final Score: " << endl;
cout << "Player 1: " << player_score << endl;
cout << "CPU: " << CPU_score << endl << endl << endl;
}
void Two_Player(int games){
int p1_score = 0;
int p2_score = 0;
int p1_input;
int p2_input;
int round_num = 1;
bool valid_input;
system("cls");
while (p1_score < games && p2_score < games){
valid_input = false;
cout << "Round " << round_num << endl;
cout << "------------------------" << endl;
cout << "\tScores:" << endl;
cout << "Player 1: " << p1_score << endl;
cout << "Player 2: " << p2_score << endl << endl << endl;
do{
cout << "1) Rock" << endl <<
"2) Paper" << endl <<
"3) Scissors" << endl << endl;
cout << "Your turn Player 1! Make a selection from the numbers above." << endl
<< "Selection: ";
cin >> p1_input;
cout << endl;
valid_input = check_Input(p1_input);
} while(valid_input == false);
valid_input = false;
system("cls");
cout << "Round " << round_num << endl;
cout << "------------------------" << endl;
cout << "\tScores:" << endl;
cout << "Player 1: " << p1_score << endl;
cout << "Player 2: " << p2_score << endl << endl << endl;
do{
cout << "1) Rock" << endl <<
"2) Paper" << endl <<
"3) Scissors" << endl << endl;
cout << "Your turn Player 2! Make a selection from the numbers above." << endl
<< "Selection: ";
cin >> p2_input;
cout << endl;
valid_input = check_Input(p2_input);
} while(valid_input == false);
system("cls");
decide_winner(p1_input, p2_input, p1_score, p2_score);
round_num++;
}
cout << endl << "Please wait to continue" << endl;
this_thread::sleep_for(chrono::seconds(2));
system("cls");
if (p1_score == games){
cout << "Congrats Player 1! You have won the game!" << endl;
}
else{
cout << "Congrats Player 2! You have won the game!" << endl << endl;
}
cout << "Final Score: " << endl;
cout << "Player 1: " << p1_score << endl;
cout << "Player 2: " << p2_score << endl << endl << endl;
}
/*
The value of 1 represent Rock
The value of 2 represent Paper
The value of 3 represent Scissors
*/
// The CPU is always going to be player Two
void decide_winner(int pOne_Input, int pTwo_Input, int& Score1, int& Score2){
if (pOne_Input == pTwo_Input){
cout << "It's a Tie!" << endl;
if(pOne_Input == 1){
cout << " _______ _______ \n";
cout << "---' ____) (____ '---\n";
cout << " (_____) (_____) \n";
cout << " (_____) vs (_____) \n";
cout << " (_____) (_____) \n";
cout << "---.__(_____) (_____)__.---\n";
}
else if(pOne_Input == 2){
cout << " _______ _______ \n";
cout << "---' ____)______ ______(____ '--- \n";
cout << " ________) (__________ \n";
cout << " _________) vs (___________ \n";
cout << " _________) (_________ \n";
cout << "---.____________) (____________.--- \n";
}
else{
cout << " _______ ________ \n";
cout << "---' ____)______ ______(____ '---\n";
cout << " ________) (________ \n";
cout << " ___________) vs (___________ \n";
cout << " (____) (____) \n";
cout << "---.__(___) (___)__.--- \n";
}
cout << endl << endl;
return;
}
// Tests cases if Player 1 chooses Rock
if (pOne_Input == 1){
if (pTwo_Input == 2){
cout << "It's Rock vs Paper! Paper Wins!" << endl;
cout << " _______ ________ \n";
cout << "---' ____) ______(____ '---\n";
cout << " (_____) _(__________ \n";
cout << " (_____) vs (___________ \n";
cout << " (_____) (_________ \n";
cout << "---.__(_____) (____________.--- \n";
Score2++;
cout << endl << endl;
return;
}
else if (pTwo_Input == 3){
cout << "It's Rock vs Scissors! Rock Wins!" << endl;
cout << " _______ ________ \n";
cout << "---' ____) _________(____ '---\n";
cout << " (_____) (___________ \n";
cout << " (_____) vs (_____________ \n";
cout << " (_____) (____) \n";
cout << "---.__(_____) (___)____.--- \n";
Score1++;
cout << endl << endl;
return;
}
}
// Tests cases if Player 1 chooses Paper
if (pOne_Input == 2){
if (pTwo_Input == 1){
cout << "It's Paper vs Rock! Paper Wins!" << endl;
cout << " _______ _______ \n";
cout << "---' ____)______ (____ '---\n";
cout << " ________) (_____) \n";
cout << " _________) vs (_____) \n";
cout << " _________) (_____) \n";
cout << "---.____________) (_____)__.---\n";
Score1++;
cout << endl << endl;
return;
}
else if (pTwo_Input == 3){
cout << "It's Paper vs Scissors! Scissors Wins!" << endl;
cout << " _______ _______ \n";
cout << "---' ____)______ _________(____ '---\n";
cout << " ________) (___________ \n";
cout << " _________) vs (_____________ \n";
cout << " _________) (____) \n";
cout << "---.____________) (___)____.--- \n";
Score2++;
cout << endl << endl;
return;
}
}
// Tests cases if Player 1 chooses Scissors
if (pOne_Input == 3){
if (pTwo_Input == 1){
cout << "It's Scissors vs Rock! Rock Wins!" << endl;
cout << " _______ ________ \n";
cout << "---' ____)______ (____ '---\n";
cout << " ________) (_____) \n";
cout << " ___________) vs (_____) \n";
cout << " (____) (_____) \n";
cout << "---.__(___) (_____)__.---\n";
Score2++;
cout << endl << endl;
return;
}
else if (pTwo_Input == 2){
cout << "It's Scissors vs Paper! Scissors Wins!" << endl;
cout << " _______ ________ \n";
cout << "---' ____)______ ______(____ '---\n";
cout << " ________) ( _________ \n";
cout << " ___________) vs (___________ \n";
cout << " (____) (_________ \n";
cout << "---.__(___) (____________.--- \n";
Score1++;
cout << endl << endl;
return;
}
}
cout << endl <<"Error: Hit end of Decide Winner Function";
}
bool check_Input(int RPS_Choice){
if (RPS_Choice == 1 || RPS_Choice == 2 || RPS_Choice == 3){
return true;
}
else{
return false;
}
}