-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
172 lines (168 loc) · 5.57 KB
/
Source.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
#include <ctime>
#include "service.h"
#include "mechanics.h"
//std::string textPath = "text\\";
int main()
{
const int kAcreCostUpperLimit = 26;
const int kAcreCostLowerLimit = 17;
srand(time(0));
int iCommandInput = 0;
/*City city;*/
Turn turn;
while (1)
{
while ((iCommandInput != 1) && (iCommandInput != 2))
{
system("cls");
PrintMainMenu();
std::string sInputCommand;
std::cin >> sInputCommand;
iCommandInput = ConvertInput(sInputCommand);
switch (iCommandInput)
{
case 1:
system("cls");
LoadFromFile(turn);
break;
case 2:
{
system("cls");
std::cout << "Please, type in the name for your great city:\n";
std::string name;
std::cin >> name;
system("cls");
Start(turn, name);
}
break;
case 3:
system("cls");
PrintRules();
WaitUntilEnterPressed();
break;
case 4:
return 0;
default:
std::cout << "Invalid input! Press Enter.\n";
WaitUntilEnterPressed();
break;
}
}
bool hasNotLost = 1;
do
{
Input input = {0, 0, 0, 0};
iCommandInput = 0;
turn.acreCost = kAcreCostLowerLimit + rand() % kAcreCostUpperLimit + 1;
while (iCommandInput != 5)
{
system("cls");
PrintCityStats(turn.city);
if (turn.turnNumber > 1)
PrintTurnResults(turn);
else
{
std::cout << "My Lord, I welcome you as the new ruler of our city of " << turn.city.name << "!\n";
}
std::cout << "Each acre of land costs " << turn.acreCost << " bushels.\n";
std::cout << "\nMy lord, I am listening to your orders!\n";
std::cout << "\t1. Purchase some land.\n\t2. Sell some land\n\t3. Let citizens have some wheat for food. \n\t4. Sow some land with wheat.\n\t5. Finish\n\t0. Quit the game\n\n";
std::cout << "Choose the command by pressing the number + ENTER. Previous order will be revoked.\n\nYour active orders:\n";
std::cout << "\tLand to purchase: " << input.acresToBuy << " acres.\n";
std::cout << "\tLand to sell: " << input.acresToSell << " acres.\n";
std::cout << "\tWheat for food: " << input.bushelsToEat << " bushels.\n";
std::cout << "\tLand to sow: " << input.acresToSow << " acres.\n";
std::string sCommandInput;
std::cin >> sCommandInput;
iCommandInput = ConvertInput(sCommandInput);
switch (iCommandInput)
{
case 1:
std::cout << "Purchase some land... How many acres?\n";
std::cin >> input.acresToBuy;
if (input.acresToBuy * turn.acreCost > turn.city.wheat + input.acresToSell * turn.acreCost)
{
std::cout << "\nMy Lord, we don't have enough wheat. I am begging, rethink your order!\nPress ENTER and try again\n";
input.acresToBuy = 0;
WaitUntilEnterPressed();
}
break;
case 2:
std::cout << "Sell some land... How many acres?\n";
std::cin >> input.acresToSell;
if (input.acresToSell > turn.city.area + input.acresToBuy)
{
std::cout << "\nMy Lord, we don't have enough land. I am begging, rethink your order!\nPress ENTER and try again\n";
input.acresToSell = 0;
WaitUntilEnterPressed();
}
break;
case 3:
std::cout << "Give out some wheat for food... How many bushels?\n";
std::cin >> input.bushelsToEat;
if (input.bushelsToEat > turn.city.wheat + input.acresToSell * turn.acreCost)
{
std::cout << "\nMy Lord, we don't have enough wheat. I am begging, rethink your order!\nPress ENTER and try again\n";
input.bushelsToEat = 0;
WaitUntilEnterPressed();
}
break;
case 4:
std::cout << "Sow some land with wheat.. How many acres?\n";
std::cin >> input.acresToSow;
if (input.acresToSow > turn.city.area + input.acresToBuy)
{
std::cout << "\nMy Lord, we don't have enough land. I am begging, rethink your order!\nPress ENTER and try again\n";
input.acresToSow = 0;
WaitUntilEnterPressed();
}
else if (turn.city.population * 10 < input.acresToSow)
{
std::cout << "\nMy Lord, we don't have enough people for that much work. I am begging you, rethink your order!\nPress ENTER and try again\n";
input.acresToSow = 0;
WaitUntilEnterPressed();
}
break;
case 5:
break;
case 0:
{
std::cout << "Are you leaving so soon, my Lord?\nPress 0 + ENTER to save the progress; press any other key + ENTER to return to the game.\n";
std::string sCommandInput_;
std::cin >> sCommandInput_;
if (ConvertInput(sCommandInput_) == 0)
{
if (Save(turn))
std::cout << "\nProgress saved. Press ENTER to quit.\n";
else
std::cout << "\nSaving error. Press ENTER to quit.";
WaitUntilEnterPressed();
return 0;
}
}
break;
default:
std::cout << "I do not understand you, my Lord. Press ENTER and try again";
WaitUntilEnterPressed();
break;
}
}
hasNotLost = UpdateParam(turn, input);
}
while (turn.turnNumber < 11 && hasNotLost);
if (!hasNotLost)
{
system("cls");
std::cout << "My Lord! There is not enough food on out storages! Many have died of hunger. The others are very angry. These filthy\npeasants gathered at the front gate of your castle and they want your head on a pole. I am afraid we have to flee!\n\n";
std::cout << "GAME OVER!\nPress ENTER to return to the main menu.\n";
WaitUntilEnterPressed();
}
else
{
system("cls");
PrintTotalResults(turn.city);
std::cout<< "\nPress ENTER to return to the main menu.\n";
WaitUntilEnterPressed();
}
}
}