-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainDriver.cpp
More file actions
217 lines (192 loc) · 6.32 KB
/
Copy pathMainDriver.cpp
File metadata and controls
217 lines (192 loc) · 6.32 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
// Group member: Riley Wu and Nidhi Prasad.
#include "Board.h"
#include "Player.h"
#include "Tile.h"
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <sstream>
using namespace std;
// Here we first define all the functions that will be declared later.
// creating a struct so the main_menu function can return both in player class and board class
// because I made a function that doesn't change the actual value, we need to update it every time as it returns and we can assign it in main()
struct MenuResult {
Player player;
Board board;
};
int selectCharacter();
// initializing board and number of player
MenuResult main_menu(Player p, int turns, Board b);
// the MAIN function of the game
int main(){
Player player1;
Player player2;
int playerCount = 2;
Board board(playerCount);
//Player 1 chooses character
cout << "Player 1, please choose your character:" << endl;
int choice1 = selectCharacter();
player1.Character(choice1);
//Player 1 chooses paths
cout << "Player 1, please choose your path:" << endl;
int path1;
do {
cout << "Enter choice (1 = Cub Training, 2 = Pride Lands): ";
cin >> path1;
} while (path1 != 1 && path1 != 2);
board.setPlayerPath(0, path1);
if (path1 == 1) {
board.selectAdvisor(0);
} else {
board.advisor[0] = 0;
}
player1.selectPath(path1);
//Player 2 chooses character
cout << "Player 2, please choose your character:" << endl;
int choice2 = selectCharacter();
player2.Character(choice2);
//Player 2 chooses path
cout << "Player 2, please choose your path:" << endl;
int path2;
do {
cout << "Enter choice (1 = Cub Training, 2 = Pride Lands): ";
cin >> path2;
} while (path2 != 1 && path2 != 2);
board.setPlayerPath(1, path2);
if (path2 == 1) {
board.selectAdvisor(1);
} else {
board.advisor[1] = 0;
}
player2.selectPath(path2);
board.displayBoard();
int turns = 0;
bool theEND = true;
// MAIN GAME!
// While the two player's position is not at the end, game continues
while (theEND){
turns = turns % 2;
if (turns == 0){
cout << "Player 1's turn: " << endl;
MenuResult result = main_menu(player1, 0, board);
player1 = result.player;
board = result.board;
} else if (turns == 1) {
cout << "Player 2's turn: " << endl;
MenuResult result = main_menu(player2, 1, board);
player2 = result.player;
board = result.board;
}
turns++;
// condition to end the while loop
if (board.getPlayerPosition(0) >= 51 && board.getPlayerPosition(1) >= 51){
theEND = false;
}
}
// after the game ENDS
//Calculate pride points
player1.calculateFinalPoints();
player2.calculateFinalPoints();
// using a sorting algorithm to find the winner.
int winner = board.findWinner(player1.getPridePoints(), player2.getPridePoints());
cout << "Here's the winner board: " << endl;
if (winner == 0){
cout << "Congrats "<< player1.getName() << " (Player 1), you have won! " << endl;
cout << "Here's the final stats: " << endl;
cout << player1.getName() << ": " << endl;
player1.Progress();
cout << player2.getName() << ": " << endl;
player2.Progress();
player1.printWinnerToFile(); // Printing the result to file named "game_results.txt"
}else {
cout << "Congrats "<< player2.getName() << " (Player 2), you have won! " << endl;;
cout << "Here's the final stats: " << endl;
cout << player2.getName() << ": " << endl;
player2.Progress();
cout << player1.getName() << ": " << endl;
player1.Progress();
player2.printWinnerToFile();
}
}
//select character
int selectCharacter(){
int choice;
Player player;
cout << "Choose your character:\n";
cout << "1. Apollo\n";
cout << "2. Mane\n";
cout << "3. Elsa\n";
cout << "4. Zuri\n";
cout << "5. Roary\n";
cout << "6. Enter your own character\n";
do { // if the user don't pick between number 1-6
cout << "Enter choice (1-6): ";
cin >> choice;
if (choice < 1 || choice > 6) {
cout << "Invalid choice. Try again.\n";
}
} while (choice < 1 || choice > 6);
switch (choice) {
case 1:
cout << "You chose Apollo!\n";
break;
case 2:
cout << "You chose Mane!\n";
break;
case 3:
cout << "You chose Elsa!\n";
break;
case 4:
cout << "You chose Zuri!\n";
break;
case 5:
cout << "You chose Roary!\n";
break;
case 6:
break;
}
return choice;
}
// Main menu function, while the game still plays, this menu shows every time when it's someone's turn.
MenuResult main_menu(Player p, int turns, Board b) {
int input;
cout << "Main Menu: Select an option to continue" << endl;
cout << "1. Check Player Progress (1)" << endl;
cout << "2. Review Character (2)" << endl;
cout << "3. Check Position (3)" << endl;
cout << "4. Review your Advisor (4)" << endl;
cout << "5. Move Forward (5)" << endl;
cout << "6. Exit the Game (6)" << endl;
cout << "Please choose an option using the corresponding number:" << endl;
cin >> input;
switch (input) {
case 1:
p.Progress();
break;
case 2:
p.nameAge();
break;
case 3:
cout << "Your position on the board: ";
cout << b.getPlayerPosition(turns) << endl;
break;
case 4:
b.reviewAdvisor(turns); // get the advisor from board class.
break;
case 5:
b.movePlayer(turns); // move player in Board class, updating the position
if (b.getPlayerPosition(turns) > 51){
b.setPlayerPosition(turns, 51);
}
b.HandleTileEffects(p, turns); // Handles effects
b.displayBoard();
break;
case 6:
exit(0); // ends the program cleanly, for now
default:
cout << "Please enter a valid number" << endl;
break;
}
return {p, b};
}