-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (63 loc) · 2.08 KB
/
Copy pathmain.cpp
File metadata and controls
74 lines (63 loc) · 2.08 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
#include "Stronghold.h"
#include <iostream>
#include <limits>
using namespace std;
int main() {
// Seed random number generator
srand(static_cast<unsigned int>(time(0)));
// Welcome message
cout << "Welcome to Stronghold: Rule Your Medieval Kingdom!" << endl;
// Initialize kingdom
string kingdomName;
cout << "Enter your kingdom's name: ";
getline(cin, kingdomName);
if (kingdomName.empty()) {
kingdomName = "Default Kingdom";
}
string kingName;
cout << "Enter your king's name: ";
getline(cin, kingName);
if (kingName.empty()) {
kingName = "King Ali";
}
Kingdom kingdom(kingdomName);
kingdom.setRuler(make_unique<King>(kingName, 70, 60, 50, 80));
// Main game loop
bool running = true;
int choice;
while (running && !kingdom.isGameOver()) {
clearScreen();
displayMainMenu();
// Get user input with validation
if (cin >> choice && choice >= 1 && choice <= 13) {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
running = processMenuChoice(choice, kingdom);
if (choice != 11) {
clearScreen();
}
else if (choice != 12) {
clearScreen();
}
}
else {
cout << "Invalid input! Please enter a number between 1 and 13." << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
pauseScreen();
clearScreen();
}
// Check game over conditions
if (kingdom.isGameOver()) {
cout << "\n===== GAME OVER =====" << endl;
cout << "Your kingdom has fallen!" << endl;
cout << "Final Score: " << kingdom.getScore() << endl;
cout << "Years Ruled: " << kingdom.getGameYear() - 1 << endl;
running = false;
}
}
// Final message
if (!kingdom.isGameOver()) {
cout << "\nThank you for playing Stronghold!" << endl;
}
return 0;
}