-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain (2).cpp
650 lines (622 loc) · 19.5 KB
/
main (2).cpp
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/* **********************************************************************
-----
Author: Tony Fountain
Purpose: Created because I wanted to challenge myself, learn, and
expand knowledge.
start date: 12/31/2019
finish date: 01/05/2020
Description of program: It allows the user to input a name to be used as
the account, play 1v1, play vs 2 others so 1v1v1, and a ranked system
using 1v1 with a simple ranking score gain equation in place.
-----
********************************************************************** */
#include <iostream>
#include <string>
#include <unistd.h>
#include <cstdlib>
using namespace std;
//-----
struct RankedPlay
{
string name;
bool winRankedStreak(int streakCh);
void updateRanked(int wlCheck);
int rankedStreakChUpd(int wlCheck);
int getRanked();
private:
double rankScore = 0;
int streak = 0;
};
RankedPlay player1;
RankedPlay computer1;
//-----
void welcomeScreen();
void proceed();
void menuSelect();
void genProfile();
void selOption(int selector);
void opt1();
void opt2();
void opt3();
void opt4();
int rpcAi();
void checkWinLose(int optCompare);
void endOpt1();
void checkWL1v1v1(int playerSel, int ai1, int ai2);
void endOpt2();
void settleTie();
void initTieAi();
void checkWinLoseAi(int opponent1, int opponent2);
bool rerollCheck(int chPlayer, int chAi1,int chAi2);
void invRerollAi(int play1, int &invAi1, int &invAi2);
void checkWinLoseRanked(int optCompare);
void endOpt3();
//-----
int main()
{
srand(time(0));
RankedPlay player1;
genProfile();
//ai for ranked play
computer1.name = "Suzora Kunitsuna";
welcomeScreen();
proceed();
menuSelect();
return 0;
}
//-----
void welcomeScreen()
{
cout << "Welcome to Rock/Paper/Scissors!" << endl;
}
//-----
void proceed()
{
string ent;
cout << "Press ENTER to proceed";
// cin.ignore(); // used if there was a 'cin >>' statement before it
getline (cin, ent);
}
//-----
void menuSelect()
{
cout << "Rock Paper Scissors Version 1." << endl;
cout << "Enter the number that comes after 'Option' to select." << endl;
cout << "Option 1. 1v1" << endl;
cout << "Option 2. 1v1v1" << endl;
cout << "Option 3. Ranked 1v1" << endl;
cout << "Option 4. Quit game" << endl;
cout << "Current Ranked 1v1 rating: " << player1.getRanked() << endl;
int selNum;
cout << "Enter Option #: ";
cin >> selNum;
selOption(selNum);
}
//-----
void selOption(int selector)
{
do
{
if(selector == 1)
{// 1v1
opt1();
proceed();
}
if(selector == 2)
{// 1v1v1
opt2();
}
if(selector == 3)
{// ranked 1v1
opt3();
}
if(selector == 4)
{// quit game option
return;
}
}while(selector > 4 || selector < 1);
}
//-----
void genProfile()
{
cout << "Creating player profile. Enter name: ";
getline (cin, player1.name);
// player1.rankScore = 0;
}
//-----
void opt1()
{
cout << "Setting up game mode.." << endl;
cout << endl;
cout << "Opponent(s): Azuri Kamenari, world renowned Rock Paper Scissors god!" << endl;
sleep(1);
cout << "Raised up in the slums, she had no other option but to take up the skill that allowed her a better life." << endl;
cout << "Match ready: 1. Rock 2. Paper 3. Scissors" << endl;
cout << "Enter a number with corresponding action: ";
int rpcSelOpt1;
cin >> rpcSelOpt1;
checkWinLose(rpcSelOpt1);
endOpt1();
}
//-----
void opt2()
{
// p1 == ai1, p1 == ai2 means ai1 == ai2 by default
cout << "Setting up game mode.." << endl;
cout << endl;
cout << "Opponent(s): Opponent1 and Opponent2" << endl;
sleep(1);
cout << "Match ready: 1. Rock 2. Paper 3. Scissors" << endl;
cout << "Enter a number with corresponding action: ";
cout << "Enter action #: ";
int rpcSelOpt2;
cin >> rpcSelOpt2;
int bot1 = rpcAi(), bot2 = rpcAi();
cout << player1.name << ": " << rpcSelOpt2 << " Opponent1: " << bot1 << " Opponent2: " << bot2 << endl;
if( rerollCheck(rpcSelOpt2, bot1, bot2) )
{
invRerollAi(rpcSelOpt2, bot1, bot2);
}
checkWL1v1v1( rpcSelOpt2, bot1, bot2 );
}
//-----
void opt3()
{
cout << "Setting up game mode.." << endl;
cout << endl;
cout << "Opponent(s): " << computer1.name << endl;
sleep(1);
cout << "Match ready: 1. Rock 2. Paper 3. Scissors" << endl;
cout << "Enter a number with corresponding action: ";
int rpcSelOpt3;
cin >> rpcSelOpt3;
checkWinLoseRanked(rpcSelOpt3);
}
//-----
void opt4()
{
return;
}
//-----
int rpcAi()
{// 1 is rock, 2 is paper, 3 is scissors
int ranNum;
ranNum = rand() % 3 + 1;
return ranNum;
}
//-----
void checkWinLose(int optCompare)
{
int aiNum = rpcAi();
if( optCompare == aiNum )
{// tie if they're the same value
cout << "Tie" << endl;
}
else if( optCompare == 2 && aiNum == 1)
{// playerPaper vs aiRock = playerPaper
cout << "Congratulations! You win with paper against your opponent's rock!" << endl;
}
else if( optCompare == 1 && aiNum == 2)
{// playerRock vs aiPaper = aiPaper
cout << "You lose. You had rock verses your opponent's paper." << endl;
}
else if( optCompare == 1 && aiNum == 3)
{// playerRock vs aiScissors = playerRock
cout << "Congratulations! You win with rock against your opponent's scissors!" << endl;
}
else if( optCompare == 3 && aiNum == 1)
{// playerScissors vs aiRock = aiRock
cout << "You lose. You had scissors verses your opponent's rock." << endl;
}
else if( optCompare == 3 && aiNum == 2)
{// playerScissors vs aiPaper = playerScissors
cout << "Congratulations! You win with scissors against your opponent's paper!" << endl;
}
else
// unspoken of if-statement which is ( optCompare == 2 && aiNum == 3)
{// playerPaper vs aiScissors = aiScissors
cout << "You lose. You had paper verses your opponent's scissors ." << endl;
}
}
//-----
void endOpt1()
{
int endSel;
cout << "Option 1. Play again " << endl;
cout << "Option 2. Game Menu" << endl;
cout << "Enter option #: ";
cin >> endSel;
if(endSel == 1)
{
opt1();
}
else
{
menuSelect();
}
}
//-----
void checkWL1v1v1(int playerSel, int ai1, int ai2)
{
/*if paper wins..*/
if( ( (playerSel + ai1) == ai2 && ai2 == 2 ) || ( playerSel == (ai1 + ai2) && playerSel == 2 ) ||
( (ai1 - playerSel) == ai2 && ai1 == 2 ) || ( (playerSel - ai1) == ai2 && ai1 == 1 ) )
{
if(playerSel == ai1 && ai2 == 2)
{
cout << "Opponent2 had paper and won against Opponent1 and " << player1.name << "'s rock." << endl;
endOpt2();
}/*end inner if*/
else if(playerSel == 2 && ai1 == ai2)
{
cout << player1.name << " had paper against Opponent1 and Opponent2's rock." << endl;
endOpt2();
}/*end else if*/
/*unspoken of else if playerSel == ai2 && ai1 == 2*/
else
{
cout << "Opponent1 had paper and won against Opponent2 and " << player1.name << "'s rock." << endl;
endOpt2();
}/*end else*/
}/*end outer if*/
else if( (playerSel == 1 && ai1 == 2 && ai2 == 2) || (playerSel == 2 && ai1 == 2 && ai2 == 1) || (playerSel == 2 && ai1 == 1 && ai2 == 2))
{
if(playerSel == 1)
{
cout << "Opponent1 and Opponent2 had paper and won against " << player1.name << "'s rock." << endl;
initTieAi();
endOpt2();
}/*end if*/
else if(ai2 == 1)
{
cout << player1.name << " and Opponent1 won with paper against Opponent2's rock." << endl;
settleTie();
endOpt2();
}/*end else if*/
/*unspoken of if ai1 == 1*/
else
{
cout << player1.name << " and Opponent2 had paper against Opponent1's rock." << endl;
settleTie();
endOpt2();
}
}/*end else if*/
/*if it ties..*/
else if( playerSel == ai1 && playerSel == ai2)
{
if(playerSel == 1)
{
cout << "Tie. All subjects had rock." << endl;
endOpt2();
}/*end if*/
if(playerSel == 2)
{
cout << "Tie. All subjects had paper." << endl;
endOpt2();
}/*end if*/
if(playerSel == 3)
{
cout << "Tie. All subjects had scissors." << endl;
endOpt2();
}/*end if*/
}/*end else if*/
/*if rock wins..*/
else if( (ai2 - ai1) == (playerSel + ai1) || (playerSel - ai1) == (ai1 + ai2) || (playerSel == 3 && ai1 == 1 && ai2 == 3) || (playerSel == 1 && ai1 == 3
&& ai2 == 3) || (playerSel == 3 && ai1 == 3 && ai2 == 1) || (playerSel == 1 && ai1 == 3 && ai2 == 1) )
{
if(playerSel == 1 && ai1 == 1 && ai2 == 3)
{
cout << player1.name << " and Opponent1 had rock and won against Opponent2's scissors." << endl;
settleTie();
endOpt2();
}/*end if*/
if(playerSel == 3 && ai1 == 1 && ai2 == 1)
{
cout << "Opponent1 and Opponent2 had rock against " << player1.name << "'s scissors." << endl;
initTieAi();
endOpt2();
}/*end if*/
if(playerSel == 3 && ai1 == 1 && ai2 == 3)
{
cout << "Opponent1 had rock and won against Opponent2 and " << player1.name << "'s scissors." << endl;
endOpt2();
}/*end if*/
if(playerSel == 1 && ai1 == 3 && ai2 == 3)
{
cout << player1.name << " had rock and won against Opponent1 and Opponent2's scissors" << endl;
endOpt2();
}/*end if*/
if(playerSel == 3 && ai1 == 3 && ai2 == 1)
{
cout << "Opponent2 had rock and won against Opponent1 and " << player1.name << "'s scissors" << endl;
endOpt2();
}/*end if*/
if(playerSel == 1 && ai1 == 3 && ai2 == 1)
{
cout << player1.name << " and Opponent2 had rock and won against Opponent1's scissors." << endl;
settleTie();
endOpt2();
}/*end if*/
}/*end else if*/
/*if scissor wins..*/
else if( (playerSel == 2 && ai1 == 2 && ai2 == 3) || (playerSel == 2 && ai1 == 3 && ai2 == 2) || (playerSel == 2 && ai1 == 3 && ai2 == 3) ||
(playerSel == 3 && ai1 == 2 && ai2 == 2) || (playerSel == 3 && ai1 == 2 && ai2 == 3) || (playerSel == 3 && ai1 == 3 && ai2 == 2) )
{
if(playerSel == ai1 && ai2 == 3)
{
cout << "Opponent2 had scissors and won against Opponent1 and " << player1.name << "'s paper." << endl;
endOpt2();
}/*end if*/
else if(playerSel == ai2 && ai1 == 3)
{
cout << "Opponent1 had scissors and won against Opponent2 and " << player1.name << "'s paper." << endl;
endOpt2();
}/*end else if*/
else if(playerSel == 2 && ai1 == ai2)
{
cout << "Opponent1 and Opponent2 had scissors and won against " << player1.name << "'s paper." << endl;
initTieAi();
endOpt2();
}/*end else if*/
else if(playerSel == 3 && ai1 == ai2)
{
cout << player1.name << " had scissors against Opponent1 and Opponent2's paper." << endl;
endOpt2();
}/*end else if*/
else if(playerSel == ai2 && ai1 == 2)
{
cout << player1.name << " and Opponent2 had scissors and won against Opponent1's paper." << endl;
settleTie();
endOpt2();
}/*end else if*/
else/*unspoken of else if 332*/
{
cout << player1.name << " and Opponent1 had scissors and won against Opponent2's paper." << endl;
settleTie();
endOpt2();
}/*end else*/
}/*end else if*/
}/*end function*/
/*-----*/
void settleTie()
{
cout << "Initiating Sudden Death.." << endl;
cout << endl;
sleep(1);
cout << "Match ready: 1. Rock 2. Paper 3. Scissors" << endl;
cout << "Enter a number with corresponding action: ";
int rpcSelTie;
cin >> rpcSelTie;
checkWinLose(rpcSelTie);
}
//-----
void endOpt2()
{
int endSel;
cout << "Option 1. Play again " << endl;
cout << "Option 2. Game Menu" << endl;
cout << "Enter option #: ";
cin >> endSel;
if(endSel == 1)
{
opt2();
}
else
{
menuSelect();
}
}
//-----
void initTieAi()
{
cout << "Initiating Sudden Death.." << endl;
cout << endl;
sleep(1);
cout << "Match ready: 1. Rock 2. Paper 3. Scissors" << endl;
int rpcSelTie1, rpcSelTie2;
rpcSelTie1 = rpcAi();
rpcSelTie2 = rpcAi();
cout << "Opponent1: " << rpcSelTie1 << " Opponent2: " << rpcSelTie2 << endl;
checkWinLoseAi(rpcSelTie1, rpcSelTie2);
}
//-----
void checkWinLoseAi(int opponent1, int opponent2)
{
if( opponent1 == opponent2 )
{// tie if they're the same value
cout << "Opponent1 and Opponent2 Tied." << endl;
}
else if( opponent1 == 2 && opponent2 == 1)
{// aiPaper vs aiRock = aiPaper
cout << "Opponent1 Wins. Opponent1 had paper and Opponent2 had rock." << endl;
}
else if( opponent1 == 1 && opponent2 == 2)
{// aiRock vs aiPaper = aiPaper
cout << "Opponent2 Wins. Opponent2 had paper and Opponent1 had rock." << endl;
}
else if( opponent1 == 1 && opponent2 == 3)
{// aiRock vs aiScissors = aiRock
cout << "Opponent1 Wins. Opponent1 had rock and Opponent2 had scissors." << endl;
}
else if( opponent1 == 3 && opponent2 == 1)
{// aiScissors vs aiRock = aiRock
cout << "Opponent2 Wins. Opponent2 had rock and Opponent1 had scissors." << endl;
}
else if( opponent1 == 3 && opponent2 == 2)
{// aiScissors vs aiPaper = aiScissors
cout << "Opponent1 Wins. Opponent1 had scissors and Opponent2 had paper." << endl;
}
else
/*unspoken of if-statement which is ( optCompare == 2 && aiNum == 3)*/
{/*aiPaper vs aiScissors = aiScissors*/
cout << "Opponent2 Wins. Opponent2 had scissors and Opponent1 had paper." << endl;
}
}
//-----
bool rerollCheck(int chPlayer, int chAi1,int chAi2)
{
if( (chPlayer == 1 && chAi1 == 2 && chAi2 == 3) || (chPlayer == 1 && chAi1 == 3 && chAi2 == 2) || (chPlayer == 2 && chAi1 == 1 && chAi2 == 3)
|| (chPlayer == 2 && chAi1 == 3 && chAi2 == 1) || (chPlayer == 3 && chAi1 == 1 && chAi2 == 2) || (chPlayer == 3 && chAi1 == 2 && chAi2 == 1) )
{
// cout << "TEST REROLL TRUE" << endl;
return true;
}/*end if*/
else
{
// cout << "TEST REROLL FALSE" << endl;
return false;
}/*end else*/
}
/*-----*/
void invRerollAi(int play1, int &invAi1,int &invAi2)
{
cout << endl;
cout << "Everyone had different options, rerolling Oppenent1 and Opponent2.." << endl;
for(int i = rand() % 3 + 1, j = rand() % 3 + 1; rerollCheck(play1, invAi1, invAi2); i = rand() % 3 + 1, j = rand() % 3 + 1 )
{
invAi1 = i;
invAi2 = j;
}
sleep(1);
cout << endl;
cout << player1.name << ": " << play1 << " Opponent1: " << invAi1 << " Opponent2: " << invAi2 << endl;
}
/*-----*/
void checkWinLoseRanked(int optCompare)
{
int aiNum = rpcAi();
int winloseCheck;
if( optCompare == aiNum )
{// tie if they're the same value
cout << "Tie" << endl;
/*0 means it resets the win streak*/
winloseCheck = 2;
player1.updateRanked(winloseCheck);
cout << "Adjusted rank for: -" << player1.name << "- Ranked 1v1 rating: " << player1.getRanked() << endl << endl;;
endOpt3();
}
else if( optCompare == 2 && aiNum == 1)
{// playerPaper vs aiRock = playerPaper
cout << "Congratulations! You win with paper against your opponent's rock!" << endl << endl;
/*1 means.......*/
winloseCheck = 1;
player1.updateRanked(winloseCheck);
cout << "Adjusted rank for: -" << player1.name << "- Ranked 1v1 rating: " << player1.getRanked() << endl << endl;
endOpt3();
}
else if( optCompare == 1 && aiNum == 2)
{// playerRock vs aiPaper = aiPaper
cout << "You lose. You had rock verses your opponent's paper." << endl << endl;
winloseCheck = 0;
player1.updateRanked(winloseCheck);
cout << "Adjusted rank for: -" << player1.name << "- Ranked 1v1 rating: " << player1.getRanked() << endl << endl;
endOpt3();
}
else if( optCompare == 1 && aiNum == 3)
{// playerRock vs aiScissors = playerRock
cout << "Congratulations! You win with rock against your opponent's scissors!" << endl << endl;
winloseCheck = 1;
player1.updateRanked(winloseCheck);
cout << "Adjusted rank for: -" << player1.name << "- Ranked 1v1 rating: " << player1.getRanked() << endl << endl;
endOpt3();
}
else if( optCompare == 3 && aiNum == 1)
{// playerScissors vs aiRock = aiRock
cout << "You lose. You had scissors verses your opponent's rock." << endl << endl;
winloseCheck = 0;
player1.updateRanked(winloseCheck);
cout << "Adjusted rank for: -" << player1.name << "- Ranked 1v1 rating: " << player1.getRanked() << endl << endl;
endOpt3();
}
else if( optCompare == 3 && aiNum == 2)
{// playerScissors vs aiPaper = playerScissors
cout << "Congratulations! You win with scissors against your opponent's paper!" << endl << endl;
winloseCheck = 1;
player1.updateRanked(winloseCheck);
cout << "Adjusted rank for: -" << player1.name << "- Ranked 1v1 rating: " << player1.getRanked() << endl << endl;
endOpt3();
}
else
// unspoken of if-statement which is ( optCompare == 2 && aiNum == 3)
{// playerPaper vs aiScissors = aiScissors
cout << "You lose. You had paper verses your opponent's scissors ." << endl << endl;
winloseCheck = 0;
player1.updateRanked(winloseCheck);
cout << "Adjusted rank for: -" << player1.name << "- Ranked 1v1 rating: " << player1.getRanked() << endl << endl;
endOpt3();
}
}
/*-----*/
bool RankedPlay::winRankedStreak(int streakCh)
{
if(streakCh == 2)
{
streak = 0;
return false;
}
if(streakCh == 1 && streak == 0)
{
streak = 1;
return true;
}
if(streakCh == 1 && streak == 1)
{
streak = 1;
rankScore = rankScore + 1;
return true;
}
if(streakCh == 0)
{
streak = 0;
return false;
}
}
/*-----*/
void RankedPlay::updateRanked(int wlCheck)
{
if(wlCheck == 0)
{
rankScore = rankScore - 1;
winRankedStreak(0);
}
if(wlCheck == 1)
{
rankScore = rankScore + 1;
winRankedStreak(1);
}
if(wlCheck == 2)
{
winRankedStreak(2);
}
if( getRanked() < 0)
{
rankScore = 0;
}
// player1.winRankedStreak();
}
/*-----*/
int RankedPlay::rankedStreakChUpd(int wlCheck)
{
}
/*-----*/
int RankedPlay::getRanked()
{
return rankScore;
}
/*-----*/
void endOpt3()
{
int endSel;
cout << "Option 1. Play again " << endl;
cout << "Option 2. Game Menu" << endl;
cout << "Enter option #: ";
cin >> endSel;
if(endSel == 1)
{
opt3();
}
else
{
menuSelect();
}
}