Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
213 lines (166 loc) · 5.62 KB
/
Copy pathmain.cpp
File metadata and controls
213 lines (166 loc) · 5.62 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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include "Player.h"
#include "Event.h"
#include "Dish.h"
#include "Meatballs.h"
#include "RedPasta.h"
#include "Beef.h"
#include "IceCream.h"
using namespace std;
void saveProgress(Player& player, int level, Dish* dishes[], string& filename) {
ofstream outFile(filename);
if (!outFile) {
cout << "Error: Could not open file for writing." << endl;
return;
}
outFile << level << endl;
outFile << player.getXP() << endl;
outFile << player.getIncome() << endl;
for (int i = 0; i < NUM_DISHES; ++i) {
outFile << dishes[i]->getProficiency() << endl;
}
outFile.close();
cout << "Progress saved to '" << filename << "'!" << endl;
}
void loadProgress(Player& player, int& level, Dish* dishes[]) {
string filename;
cout << "Enter filename to load progress from (e.g., save.txt): ";
cin >> filename;
ifstream inFile(filename);
if (!inFile) {
cout << "Error: Could not open file '" << filename << "'." << endl;
return;
}
int xp, prof;
double income;
inFile >> level;
inFile >> xp;
inFile >> income;
player.resetIncome();
player.gainXP(xp);
player.addIncome(income);
for (int i = 0; i < NUM_DISHES; ++i) {
inFile >> prof;
for (int j = 0; j < prof; ++j) {
dishes[i]->increaseProficiency();
}
}
inFile.close();
cout << "Progress successfully loaded from '" << filename << "'!" << endl;
}
int main() {
srand(time(0));
Player player;
int level = 1;
bool running = true;
bool firstGame = true;
Dish* dishes[NUM_DISHES];
dishes[0] = new Meatballs();
dishes[1] = new RedPasta();
dishes[2] = new Beef();
dishes[3] = new IceCream();
do {
cout << "=== Overloaded Cook! Main Menu ===" << endl;
cout << "1. ";
if (firstGame) {
cout << "Start New Game" << endl;
} else {
cout << "Next Level" << endl;
}
cout << "2. Load Progress" << endl;
cout << "3. Save Progress" << endl;
cout << "4. Quit Game" << endl;
cout << "Choose an option: ";
int menuChoice;
cin >> menuChoice;
if (menuChoice == 1) {
cout << "--- Starting ";
if (firstGame) {
cout << "New Game";
} else {
cout << "Level " << level;
}
cout << " ---" << endl;
const double dailyQuota = 100.0 + 50.0 * (level - 1);
const int startHour = 9;
const int endHour = 21;
cout << "Daily Quota: $" << dailyQuota << endl;
for (int hour = startHour; hour <= endHour; hour++) {
cout<<endl;
cout<<endl;
cout << "---- Time: " << hour << ":00 ----" << endl;
Event::triggerRandomEvent(player);
cout << "Choose your action:" << endl;
cout << "1. Take Order" << endl;
cout << "2. Cook Order" << endl;
cout << "3. Sweep the floor" << endl;
cout << "4. Do nothing" << endl;
cout << "Choice: ";
int action;
cin >> action;
cout<<endl;
cout<<endl;
if (action == 1) {
player.takeOrder();
}
else if (action == 2) {
cout << "Which dish would you like to cook?" << endl;
for (int i = 0; i < NUM_DISHES; ++i) {
cout << i + 1 << ". ";
dishes[i]->displayInfo();
cout << endl;
}
int choice;
cout << "Enter dish number: ";
cin >> choice;
if (choice >= 1 && choice <= NUM_DISHES) {
player.cookDish(dishes, choice - 1);
} else {
cout << "Invalid dish selection." << endl;
}
}
else if (action == 3) {
player.sweep();
}
else if (action == 4) {
cout << "You chose to do nothing this hour..." << endl;
}
else {
cout << "Invalid action." << endl;
}
player.displayStats();
}
cout << "=== Day Complete ===" << endl;
if (player.getIncome() >= dailyQuota) {
cout << "Congrats! You met your quota!" << endl;
level++;
} else {
cout << "You didn't meet your quota. Try again." << endl;
}
firstGame = false;
}
else if (menuChoice == 2) {
loadProgress(player, level, dishes);
firstGame = false;
}
else if (menuChoice == 3) {
string filename;
cout << "Enter filename to save progress (e.g., save.txt): ";
cin >> filename;
saveProgress(player, level, dishes, filename);
}
else if (menuChoice == 4) {
for (int i = 0; i < NUM_DISHES; ++i)
delete dishes[i];
cout << "Thanks for playing Overloaded Cook! Bye!" << endl;
running = false;
}
else {
cout << "Invalid option." << endl;
}
} while (running);
return 0;
}