-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
677 lines (656 loc) · 30.9 KB
/
main.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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#include "RPS.h"
#include "RPS.cpp"
#include "GTN.h"
#include "GTN.cpp"
#include "brands.h"
#include "brands.cpp"
#include "player.h"
#include "player.cpp"
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
/**
* Sources:
* 1.
* I worked with Timothy to brainstorm ideas and how to implement ideas
*
* 2.
* http://www.cplusplus.com/reference/cstdlib/rand/
* used to learn how to get a random number
*
*/
int main(){
/**
* The code below creates the players, allowing them to choose their name. It then returns the names they have chosen.
*/
string choice;
int helpCondense = 1;
bool loop = true;
string playerOne;
string playerTwo;
string playerThree;
string playerFour;
cout <<"Player one, please enter your name: ";
cin >> playerOne;
std::transform(playerOne.begin(), playerOne.end(), playerOne.begin(), ::toupper);
while(loop = true){
cout << "Player two, please enter your name: ";
cin >> playerTwo;
std::transform(playerTwo.begin(), playerTwo.end(), playerTwo.begin(), ::toupper);
if(playerTwo == playerOne){
cout << "You're name cannot be the same as someone else's!\n";
}
else{
break;
}
}
while(loop = true){
cout << "Player three, please enter your name: ";
cin >> playerThree;
std::transform(playerThree.begin(), playerThree.end(), playerThree.begin(), ::toupper);
if(playerThree == playerOne || playerThree == playerTwo){
cout << "You're name cannot be the same as someone else's!\n";
}
else{
break;
}
}
while(loop = true){
cout << "Player four, please enter your name: ";
cin >> playerFour;
std::transform(playerFour.begin(), playerFour.end(), playerFour.begin(), ::toupper);
if(playerFour == playerOne || playerFour == playerThree || playerFour == playerTwo){
cout << "You're name cannot be the same as someone else's!\n";
}
else{
break;
}
}
player p1(playerOne);
player p2(playerTwo);
player p3(playerThree);
player p4(playerFour);
cout << "The players are: " << p1.getName() << ", " << p2.getName() << ", " << p3.getName() << ", and " << p4.getName() << "." << endl;
/**
* This will be the menu, where the player will be able to choose which game they want to play or quit
*/
while (loop == true){
cout << endl << "\nWhat would you like to do? Please enter 1, 2, 3, 4, 5, 6, or 7 \n1. Car Brand Knowledge\n2. Rock-Paper-Scissors\n3. Guess the Number\n4. Scores\n5. Note\n6. View all the Winners\n7. Quit\n\n";
cin >> choice;
/**
* This will be the car brand knowledge game, the brands class will be used here.
* Players must list the car brands that they know, if they can't think of anymore they can type done to move onto the next player
* All the user inputs will be case insensitive
*/
if(choice == "1"){
bool Game1 = false;
int p1Game1Points = 0;
int p2Game1Points = 0;
int p3Game1Points = 0;
int p4Game1Points = 0;
carBrands g1;
g1.setPlayers(p1.getName(), p2.getName(), p3.getName(), p4.getName());
cout << "Players are: " << g1.getPlayers(0) << ", " << g1.getPlayers(1) << ", " << g1.getPlayers(2) << ", and " << g1.getPlayers(3) << endl;
g1.openBrands("brands.txt");
cout << "Name all the car brands you know! Input 'done' when you can't think of anymore and type 'quit' to quit the game." << endl;
while(Game1 == false){
while(Game1 == false){
g1.setPlayerOneChoice();
for(int i = 0; i < 50; i++){
if (g1.getPlayerOneChoice() == g1.brands[i]){
cout << "Correct!" << endl;
p1Game1Points++;
}
}
if (g1.getPlayerOneChoice() == "done"){
cout << g1.getPlayers(0) << ", you correctly named " << p1Game1Points << " brands.\n";
break;
}
else if(g1.getPlayerOneChoice() == "quit"){
Game1 = true;
}
}
while(Game1 == false){
g1.setPlayerTwoChoice();
for(int i = 0; i < 50; i++){
if (g1.getPlayerTwoChoice() == g1.brands[i]){
cout << "Correct!" << endl;
p2Game1Points++;
}
}
if (g1.getPlayerTwoChoice() == "done"){
cout << g1.getPlayers(1) << ", you correctly named " << p2Game1Points << " brands.\n";
break;
}
else if(g1.getPlayerTwoChoice() == "quit"){
Game1 = true;
break;
}
}
while(Game1 == false){
g1.setPlayerThreeChoice();
for(int i = 0; i < 50; i++){
if (g1.getPlayerThreeChoice() == g1.brands[i]){
cout << "Correct!" << endl;
p3Game1Points++;
}
}
if (g1.getPlayerThreeChoice() == "done"){
cout << g1.getPlayers(2) << ", you correctly named " << p3Game1Points << " brands.\n";
break;
}
else if(g1.getPlayerThreeChoice() == "quit"){
Game1 = true;
break;
}
}
while(Game1 == false){
g1.setPlayerFourChoice();
for(int i = 0; i < 50; i++){
if (g1.getPlayerFourChoice() == g1.brands[i]){
cout << "Correct!" << endl;
p4Game1Points++;
}
else if(g1.getPlayerFourChoice() == "quit"){
Game1 = true;
break;
}
}
if (g1.getPlayerFourChoice() == "done"){
cout << g1.getPlayers(3) << ", you correctly named " << p4Game1Points << " brands." << endl;
break;
}
}
break;
}
if(Game1 == false){
//If one winner
if(p1Game1Points > p2Game1Points and p1Game1Points > p3Game1Points and p1Game1Points > p4Game1Points){
cout << g1.getPlayers(0) << " has won this game!";
p1.points++;
}
else if(p2Game1Points > p1Game1Points and p2Game1Points > p3Game1Points and p2Game1Points > p4Game1Points){
cout << g1.getPlayers(1) << " has won this game!";
p2.points++;
}
else if(p3Game1Points > p1Game1Points and p3Game1Points > p2Game1Points and p3Game1Points > p4Game1Points){
cout << g1.getPlayers(2) << " has won this game!";
p3.points++;
}
else if(p4Game1Points > p1Game1Points and p4Game1Points > p2Game1Points and p4Game1Points > p3Game1Points){
cout << g1.getPlayers(3) << " has won this game!";
p4.points++;
}
//Two way tie for first place
else if(p1Game1Points == p2Game1Points and p1Game1Points > p3Game1Points and p1Game1Points > p4Game1Points){
cout << g1.getPlayers(0) << " and " << g1.getPlayers(1) << " have tied! They both will earn points.";
p1.points++;
p2.points++;
}
else if(p1Game1Points > p2Game1Points and p1Game1Points == p3Game1Points and p1Game1Points > p4Game1Points){
cout << g1.getPlayers(0) << " and " << g1.getPlayers(2) << " have tied! They both will earn points.";
p1.points++;
p3.points++;
}
else if(p1Game1Points > p2Game1Points and p1Game1Points > p3Game1Points and p1Game1Points == p4Game1Points){
cout << g1.getPlayers(0) << " and " << g1.getPlayers(3) << " have tied! They both will earn points.";
p1.points++;
p4.points++;
}
else if(p2Game1Points > p1Game1Points and p2Game1Points == p3Game1Points and p2Game1Points > p4Game1Points){
cout << g1.getPlayers(1) << " and " << g1.getPlayers(2) << " have tied! They both will earn points.";
p2.points++;
p3.points++;
}
else if(p2Game1Points > p1Game1Points and p2Game1Points > p3Game1Points and p2Game1Points == p4Game1Points){
cout << g1.getPlayers(1) << " and " << g1.getPlayers(3) << " have tied! They both will earn points.";
p2.points++;
p4.points++;
}
//Three way tie for first
//Everybody except player 4
else if(p1Game1Points == p2Game1Points and p1Game1Points == p3Game1Points and p1Game1Points > p4Game1Points){
cout << g1.getPlayers(0) << " and " << g1.getPlayers(1) << " and " << g1.getPlayers(2) << " have tied! They will earn points.";
p1.points++;
p2.points++;
p3.points++;
}
//Except player 3
else if(p1Game1Points == p2Game1Points and p1Game1Points > p3Game1Points and p1Game1Points == p4Game1Points){
cout << g1.getPlayers(0) << " and " << g1.getPlayers(1) << " and " << g1.getPlayers(3) << " have tied! They will earn points.";
p1.points++;
p2.points++;
p4.points++;
}
//Except player 2
else if(p1Game1Points > p2Game1Points and p1Game1Points == p3Game1Points and p1Game1Points == p4Game1Points){
cout << g1.getPlayers(0) << " and " << g1.getPlayers(2) << " and " << g1.getPlayers(3) << " have tied! They will earn points.";
p1.points++;
p4.points++;
p3.points++;
}
//Except player 1
else if(p2Game1Points > p1Game1Points and p2Game1Points == p3Game1Points and p2Game1Points == p4Game1Points){
cout << g1.getPlayers(1) << " and " << g1.getPlayers(2) << " and " << g1.getPlayers(3) << " have tied! They will earn points.";
p4.points++;
p2.points++;
p3.points++;
}
//If all tied
else if(p1Game1Points == p2Game1Points and p1Game1Points == p3Game1Points and p1Game1Points == p4Game1Points){
cout << "Everbody tied! Everybody will earn points.";
p1.points++;
p2.points++;
p3.points++;
p4.points++;
}
}
}
/**
* If the user chooses rock paper scissors then they will decide between two players and play the game by inputting their choice. If it's a tie then
* there will be no points awarded, otherwise a point will go to the winner.
*/
else if(choice == "2"){
string rpsPlayer1;
string rpsPlayer2;
bool nameLoop = false;
RPS g2;
cout << "Because this game is Rock Paper Scissors, it can only have two players, please decide who wants to play.\n";
while(nameLoop == false){
cout << "Who is player 1? " << p1.getName() << " (1), " << p2.getName() << " (2), " << p3.getName() << " (3), or " << p4.getName() << " (4)?\n";
cin >> rpsPlayer1;
cout << "Who is player 2? " << p1.getName() << " (1), " << p2.getName() << " (2), " << p3.getName() << " (3), or " << p4.getName() << " (4)?\n";
cin >> rpsPlayer2;
if(rpsPlayer1 == rpsPlayer2){
cout<< "You cannot play against yourself!\n";
}
else if(rpsPlayer1 == "1" and rpsPlayer2 == "2"){
g2.setPlayerOne(p1.getName());
g2.setPlayerTwo(p2.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "2" and rpsPlayer2 == "1"){
g2.setPlayerOne(p2.getName());
g2.setPlayerTwo(p1.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "1" and rpsPlayer2 == "3"){
g2.setPlayerOne(p1.getName());
g2.setPlayerTwo(p3.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "3" and rpsPlayer2 == "1"){
g2.setPlayerOne(p3.getName());
g2.setPlayerTwo(p1.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "1" and rpsPlayer2 == "4"){
g2.setPlayerOne(p1.getName());
g2.setPlayerTwo(p4.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "4" and rpsPlayer2 == "1"){
g2.setPlayerOne(p4.getName());
g2.setPlayerTwo(p1.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "2" and rpsPlayer2 == "3"){
g2.setPlayerOne(p2.getName());
g2.setPlayerTwo(p3.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "3" and rpsPlayer2 == "2"){
g2.setPlayerOne(p3.getName());
g2.setPlayerTwo(p2.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "2" and rpsPlayer2 == "4"){
g2.setPlayerOne(p2.getName());
g2.setPlayerTwo(p4.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "4" and rpsPlayer2 == "2"){
g2.setPlayerOne(p4.getName());
g2.setPlayerTwo(p2.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "3" and rpsPlayer2 == "4"){
g2.setPlayerOne(p3.getName());
g2.setPlayerTwo(p4.getName());
nameLoop = true;
}
else if(rpsPlayer1 == "4" and rpsPlayer2 == "3"){
g2.setPlayerOne(p4.getName());
g2.setPlayerTwo(p3.getName());
nameLoop = true;
}
else{
cout << "Please choose the players by entering their corresponding number. 1, 2, 3, or 4.\n";
}
}
cout << g2.getPlayerOne() << " and " << g2.getPlayerTwo() << " are playing.\n";
if (g2.tie == false){
g2.setPlayerOneChoice();
g2.setPlayerTwoChoice();
cout << g2.getPlayerOne() << " chose " << g2.getPlayerOneChoice() << " and " << g2.getPlayerTwo() << " chose " << g2.getPlayerTwoChoice() << ".\n";
g2.determineWinner();
if (g2.getWinner() == p1.getName()){
p1.points++;
cout << p1.getName() <<" gets a point!";
}
else if (g2.getWinner() == p2.getName()){
p2.points++;
cout << p2.getName() <<" gets a point!";
}
else if (g2.getWinner() == p3.getName()){
p3.points++;
cout << p3.getName() <<" gets a point!";
}
else if (g2.getWinner() == p4.getName()){
p4.points++;
cout << p4.getName() <<" gets a point!";
}
}
}
/**
* If Guess the Number is chosen, all four users will have 8 tries to guess the correct "randomly" generated number. The user with the least amount of tries will win the game
*/
else if(choice == "3"){
GTN g3;
cout << "Try to guess what the random number is! ";
g3.setPlayerOne(p1.getName());
g3.setPlayerTwo(p2.getName());
g3.setPlayerThree(p3.getName());
g3.setPlayerFour(p4.getName());
cout << "Players are: " << g3.getPlayerOne() << ", " << g3.getPlayerTwo() << ", " << g3.getPlayerThree() << ", and " << g3.getPlayerFour() << endl;
g3.p1Turn();
g3.p2Turn();
g3.p3Turn();
g3.p4Turn();
if(helpCondense == 1){
if(g3.getP1Tries() < g3.getP2Tries() and g3.getP1Tries() < g3.getP3Tries() and g3.getP1Tries() < g3.getP4Tries()){
cout << g3.getPlayerOne() << " has won this game!";
p1.points++;
}
else if(g3.getP2Tries() < g3.getP1Tries() and g3.getP2Tries() < g3.getP3Tries() and g3.getP2Tries() < g3.getP4Tries()){
cout << g3.getPlayerTwo() << " has won this game!";
p2.points++;
}
else if(g3.getP3Tries() < g3.getP1Tries() and g3.getP3Tries() < g3.getP2Tries() and g3.getP3Tries() < g3.getP4Tries()){
cout << g3.getPlayerThree() << " has won this game!";
p3.points++;
}
else if(g3.getP4Tries() < g3.getP1Tries() and g3.getP4Tries() < g3.getP2Tries() and g3.getP4Tries() < g3.getP3Tries()){
cout << g3.getPlayerFour() << " has won this game!";
p4.points++;
}
//Two way tie for first place
else if(g3.getP1Tries() == g3.getP2Tries() and g3.getP1Tries() < g3.getP3Tries() and g3.getP1Tries() < g3.getP4Tries()){
cout << g3.getPlayerOne() << " and " << g3.getPlayerTwo() << " have tied! They both will earn points.";
p1.points++;
p2.points++;
}
else if(g3.getP1Tries() < g3.getP2Tries() and g3.getP1Tries() == g3.getP3Tries() and g3.getP1Tries() < g3.getP4Tries()){
cout << g3.getPlayerOne() << " and " << g3.getPlayerThree() << " have tied! They both will earn points.";
p1.points++;
p3.points++;
}
else if(g3.getP1Tries() < g3.getP2Tries() and g3.getP1Tries() < g3.getP3Tries() and g3.getP1Tries() == g3.getP4Tries()){
cout << g3.getPlayerOne() << " and " << g3.getPlayerFour() << " have tied! They both will earn points.";
p1.points++;
p4.points++;
}
else if(g3.getP2Tries() < g3.getP1Tries() and g3.getP2Tries() == g3.getP3Tries() and g3.getP2Tries() < g3.getP4Tries()){
cout << g3.getPlayerTwo() << " and " << g3.getPlayerThree() << " have tied! They both will earn points.";
p2.points++;
p3.points++;
}
else if(g3.getP2Tries() < g3.getP1Tries() and g3.getP2Tries() < g3.getP3Tries() and g3.getP2Tries() == g3.getP4Tries()){
cout << g3.getPlayerTwo() << " and " << g3.getPlayerFour() << " have tied! They both will earn points.";
p2.points++;
p4.points++;
}
//Three way tie for first
//Everybody except player 4
else if(g3.getP1Tries() == g3.getP2Tries() and g3.getP1Tries() == g3.getP3Tries() and g3.getP1Tries() < g3.getP4Tries()){
cout << g3.getPlayerOne() << " and " << g3.getPlayerTwo() << " and " << g3.getPlayerThree() << " have tied! They will earn points.";
p1.points++;
p2.points++;
p3.points++;
}
//Except player 3
else if(g3.getP1Tries() == g3.getP2Tries() and g3.getP1Tries() < g3.getP3Tries() and g3.getP1Tries() == g3.getP4Tries()){
cout << g3.getPlayerOne() << " and " << g3.getPlayerTwo() << " and " << g3.getPlayerFour() << " have tied! They will earn points.";
p1.points++;
p2.points++;
p4.points++;
}
//Except player 2
else if(g3.getP1Tries() < g3.getP2Tries() and g3.getP1Tries() == g3.getP3Tries() and g3.getP1Tries() == g3.getP4Tries()){
cout << g3.getPlayerOne() << " and " << g3.getPlayerThree() << " and " << g3.getPlayerFour() << " have tied! They will earn points.";
p1.points++;
p4.points++;
p3.points++;
}
//Except player 1
else if(g3.getP2Tries() < g3.getP1Tries() and g3.getP2Tries() == g3.getP3Tries() and g3.getP2Tries() == g3.getP4Tries()){
cout << g3.getPlayerTwo() << " and " << g3.getPlayerThree() << " and " << g3.getPlayerFour() << " have tied! They will earn points.";
p4.points++;
p2.points++;
p3.points++;
}
//If all tied
else if(g3.getP1Tries() == g3.getP2Tries() and g3.getP1Tries() == g3.getP3Tries() and g3.getP1Tries() == g3.getP4Tries()){
cout << "Everbody tied! Everybody will earn points.";
p1.points++;
p2.points++;
p3.points++;
p4.points++;
}
}
}
/**
* If scores is chosen, the scores of each player are outputted.
*/
else if(choice == "4"){
string tempHold;
//int tempPoints[4];
cout << p1.getName() << " has " << p1.points << " points.";
cout << endl << p2.getName() << " has " << p2.points << " points.";
cout << endl << p3.getName() << " has " << p3.points << " points.";
cout << endl << p4.getName() << " has " << p4.points << " points." << endl;
}
/**
* If Note is chosen, the player is able to choose from writing a new Note, getting the Note history, or clearing their Note history.
* Depending on what they choose, the chosen player is either able to write a Note, choose an index at which their Note history will be outputted, or clear the NoteHistory array.
*/
else if(choice == "5"){
string tempChoice;
string writer;
int index;
cout << "Choose an option (1, 2, or 3):" << endl;
cout << "1. Write Note" << endl << "2. See Note History" << endl << "3. Erase history" << endl;
cin >> tempChoice;
if (tempChoice == "1"){
cout << "Who is the writer?" << endl;
cin >> writer;
if (writer == p1.getName()){
p1.writeNote();
}
if (writer == p2.getName()){
p2.writeNote();
}
if (writer == p3.getName()){
p3.writeNote();
}
if (writer == p4.getName()){
p4.writeNote();
}
else{
cout << "That is not a current player! Going back to main menu.";
}
}
else if (tempChoice == "2"){
cout << "Who's history?" << endl;
cin >> writer;
if (writer == p1.getName()){
p1.getNoteHistory();
}
else if (writer == p2.getName()){
p2.getNoteHistory();
}
else if (writer == p3.getName()){
p3.getNoteHistory();
}
else if (writer == p4.getName()){
p4.getNoteHistory();
}
else{
cout << "That is not a current player! Going back to main menu.";
}
}
else if (tempChoice == "3"){
cout << "Who's history?" << endl;
cin >> writer;
if (writer == p1.getName()){
p1.clearHistory();
}
else if (writer == p2.getName()){
p2.clearHistory();
}
else if (writer == p3.getName()){
p3.clearHistory();
}
else if (writer == p4.getName()){
p4.clearHistory();
}
else{
cout << "That is not a current player! Going back to main menu.";
}
}
else{
cout << "That is not a valid option! Going back to main menu.";
}
}
/**
* This will allow the user to view all the past winners by reading into a file with the list of them.
*/
else if(choice == "6"){
string line;
int i = 0;
string winners[100];
ifstream file;
file.open("winners.txt");
if (file.is_open()){
while (getline(file, line)){
winners[i] = line;
i++;
}
file.close();
cout << "The winners are: ";
for(int j = 0; j < i; j++){
if(j == i-1){
cout << winners[j] << ".";
}
else{
cout << winners[j] << ", ";
}
}
}
else{
cout << "Unable to open file";
}
}
/**
* This will allow the user to quit, and once the user quits it will see who the final winner is
* If there is only one winner, it will also add to the list of winners, so that future players can see
* when they select option 4. If there are ties, it will only announce the winner.
*/
else if(choice == "7" || choice == "quit" || choice == "Quit"){
cout << "Thank you for playing! The winner will now be calculated and if there is only one winner, they will also be put onto the winners list.\n";
string line;
int i = 0;
string winners[100];
ifstream inFile;
inFile.open("winners.txt");
if (inFile.is_open()){
while (getline(inFile, line)){
winners[i] = line;
i++;
}
inFile.close();
}
//If one winner
if(p1.points > p2.points and p1.points > p3.points and p1.points > p4.points){
cout << p1.getName() << " has won the game!";
winners[i] = p1.getName();
int j = 0;
ofstream outFile;
outFile.open("winners.txt");
if (outFile.is_open()){
for(int j = 0; j <= i; j++){
outFile << winners[j] << endl;
}
}
outFile.close();
}
else if(p2.points > p1.points and p2.points > p3.points and p2.points > p4.points){
cout << p2.getName() << " has won the game!";
winners[i+1] = p2.getName();
}
else if(p3.points > p1.points and p3.points > p2.points and p3.points > p4.points){
cout << p3.getName() << " has won the game!";
winners[i+1] = p3.getName();
}
else if(p4.points > p1.points and p4.points > p2.points and p4.points > p3.points){
cout << p4.getName() << " has won the game!";
winners[i+1] = p4.getName();
}
//Two way tie for first place
else if(p1.points == p2.points and p1.points > p3.points and p1.points > p4.points){
cout << p1.getName() << " and " << p2.getName() << " have tied for first place!";
}
else if(p1.points > p2.points and p1.points == p3.points and p1.points > p4.points){
cout << p1.getName() << " and " << p3.getName() << " have tied for first place!";
}
else if(p1.points > p2.points and p1.points > p3.points and p1.points == p4.points){
cout << p1.getName() << " and " << p4.getName() << " have tied for first place!";
}
else if(p2.points > p1.points and p2.points == p3.points and p2.points > p4.points){
cout << p2.getName() << " and " << p3.getName() << " have tied for first place!";
}
else if(p2.points > p1.points and p2.points > p3.points and p2.points == p4.points){
cout << p2.getName() << " and " << p4.getName() << " have tied for first place!";
}
//Three way tie for first
//Everybody except player 4
else if(p1.points == p2.points and p1.points == p3.points and p1.points > p4.points){
cout << p1.getName() << " and " << p2.getName() << " and " << p3.getName() << " have tied for first place!";
}
//Except player 3
else if(p1.points == p2.points and p1.points > p3.points and p1.points == p4.points){
cout << p1.getName() << " and " << p2.getName() << " and " << p4.getName() << " have tied for first place!";
}
//Except player 2
else if(p1.points > p2.points and p1.points == p3.points and p1.points == p4.points){
cout << p1.getName() << " and " << p3.getName() << " and " << p4.getName() << " have tied for first place!";
}
//Except player 1
else if(p2.points > p1.points and p2.points == p3.points and p2.points == p4.points){
cout << p2.getName() << " and " << p3.getName() << " and " << p4.getName() << " have tied for first place!";
}
//If all tied
else if(p1.points == p2.points and p1.points == p3.points and p1.points == p4.points){
cout << "It was a 4 way tie!";
}
loop = false;
}
/**
* If an invalid choice is inputted, it will prompt the user to enter a valid choice
*/
else {
cout << endl << "Please enter a valid option." << endl;
}
}
}