-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cs
More file actions
341 lines (290 loc) · 12.2 KB
/
Copy pathMenu.cs
File metadata and controls
341 lines (290 loc) · 12.2 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
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
namespace ShoresOfEmberbay
{
public abstract class Menu
{
protected const string ActiveOption = "> ";
protected const string InactiveOption = " ";
protected int selectedOption = 1;
protected string[] options;
protected bool continueDisplay = true;
protected string? Art, Text;
protected Menu()
{
options = Array.Empty<string>();
}
public virtual void Display()
{
Console.Clear();
Console.WriteLine(Art);
Console.WriteLine(Text);
while (continueDisplay)
{
for (int i = 1; i <= options.Length; i++)
{
Console.Write((selectedOption == i ? ActiveOption : InactiveOption) + options[i - 1] + " (" + i + ")\n");
}
ConsoleKey key = Console.ReadKey(true).Key;
Console.SetCursorPosition(0, Console.CursorTop - options.Length);
Console.CursorVisible = false;
switch (key)
{
case ConsoleKey.UpArrow:
if (selectedOption > 1)
selectedOption--;
break;
case ConsoleKey.DownArrow:
if (selectedOption < options.Length)
selectedOption++;
break;
case ConsoleKey.Enter:
ParseOption(selectedOption);
break;
case ConsoleKey.D1:
case ConsoleKey.D2:
case ConsoleKey.D3:
case ConsoleKey.D4:
case ConsoleKey.D5:
case ConsoleKey.D6:
case ConsoleKey.D7:
case ConsoleKey.D8:
case ConsoleKey.D9:
ParseOption((int)key - 48);
break;
case ConsoleKey.Escape:
ParseEscapeOption();
break;
}
}
}
public virtual void ParseOption(int option)
{
// Intentionally left empty. This method must be overridden in classes inherited from Menu.
}
public virtual void ParseEscapeOption()
{
// Intentionally left empty. This method must be overridden in classes inherited from Menu.
}
}
public sealed class MainMenu : Menu
{
public MainMenu()
{
Art = GameArt.MenuLogo;
Text = "Use up/down arrow keys to select option, Enter or number keys to confirm, Esc to quit.\n";
options = new string[] {
"Play Game",
"Credits",
"Quit"
};
}
override public void ParseOption(int option)
{
switch (option)
{
case 1:
StartGame();
break;
case 2:
ShowCredits();
break;
case 3:
QuitGame();
break;
}
}
override public void ParseEscapeOption()
{
QuitGame();
}
private void StartGame()
{
Console.Clear();
Console.CursorVisible = true;
// Play intro slides
string villageText =
"The village of Emberbay is a remote settlement next to the ocean. \nIt used to be a sizable trading hub a few decades ago, \nbut due to excessive pollution and unsustainable development by local industries, \nthe village suffers from food shortages and overall poor health among the population to this day.";
string wildlifeText =
"Up until now, no attempts to restore the village have been made due to lack of interest and funding. \nHowever, according to latest reports from the on-site FRV, \nthe local marine environment is on the verge of irreversible decline and eventual extinction \ndue to extreme pollution and the actions of the local villagers in the past. \nThis is an unacceptable course of events which must be resolved immediately.";
string mayorText =
"You have been appointed as the new mayor of the village of Emberbay. \nYour task is to restore the village to a state where it can be self-sufficient and develop sustainably in the span of 12 months. \nTo ensure this, the village should have a population of at least 400 and at least 95% of the population should be healthy.";
GenericMenu villageSlide = new(GameArt.Village, villageText);
villageSlide.Display();
GenericMenu wildlifeSlide = new(GameArt.ResearchVessel, wildlifeText);
wildlifeSlide.Display();
GenericMenu mayorSlide = new(GameArt.Village, mayorText);
mayorSlide.Display();
Console.Clear();
Game game = new();
game.Play();
Console.Clear();
Console.WriteLine(Art);
Console.WriteLine(Text);
}
private void ShowCredits()
{
Console.Clear();
Console.CursorVisible = true;
string Credits =
"\"Shores of Emberbay\" was created as an SDU BSc Software Engineering project by:\n" +
"- Bobike\n" +
"- Condegall\n" +
"- danssolutions\n" +
"- Gierka\n" +
"- Ivan\n" +
"- perdita\n\n" +
"This game features ASCII art, partially or wholly created by:\n" +
"Joan Stark (jgs) - mountain backdrop for village elder's house, ocean sunset, trawler & elder portraits\n" +
"Ric_Hotchkiss_sdrc_com - village elder's house\n" +
"Steven Maddison - left side of village\n" +
"dgb/itz - docks sunset and background\n" +
"gnv - coast graphic\n" +
"JRO - scientist portrait\n" +
"OOShy - fisherman portrait and dock graphic\n" +
"Shanaka Dias (snd) - computer and table graphic";
GenericMenu credits = new(Art ?? "", Credits);
credits.Display();
Console.Clear();
Console.WriteLine(Art);
Console.WriteLine(Text);
}
private static void QuitGame()
{
Console.Clear();
Console.CursorVisible = true;
Console.WriteLine(Program.QuitMessage);
Environment.Exit(0);
}
}
public class GenericMenu : Menu // a menu with no options except 'press any key to continue' prompt, with customizable art and text
{
public GenericMenu(string art, string text)
{
Art = art;
Text = text;
}
override public void Display()
{
Console.Clear();
Console.WriteLine(Art);
Console.WriteLine(Text);
Console.WriteLine("\nPress any key to continue.");
ConsoleKey key = Console.ReadKey(true).Key;
}
}
public sealed class FishingMenu : Menu
{
private const string AssignedVillagersInfo = "Villagers ready to fish: ";
private const string FreeVillagersInfo = "Villagers waiting for assignment: ";
private const string AssignedOptionInfo = " will be fishing for ";
private readonly uint totalVillagers;
private uint freeVillagers;
private bool confirmed = false;
private readonly List<Fish> fishList = new();
public readonly List<uint> fisherList = new();
public FishingMenu(FishableLocation location, uint amount)
{
totalVillagers = freeVillagers = amount;
fishList = location.LocalFish;
for (int i = 0; i < fishList.Count; i++)
fisherList.Add(0);
// fish marked as "bycatch only" cannot be assigned to villagers and won't show up here
if (fishList.Count > 0)
options = fishList.Where(fish => fish.BycatchOnly == false).Select(fish => fish.Name ?? "").ToArray();
}
override public void Display()
{
Console.Clear();
Console.WriteLine("~~~ Fishing time! ~~~");
Console.Write(totalVillagers);
Console.WriteLine(" villagers in total have been assigned to fish in this location. " +
"Choose which type of fish each villager should try to catch.\n" +
"Use up/down arrow keys to select option, left/right arrow keys to change villager amounts, Enter to confirm.\n");
while (continueDisplay)
{
Console.WriteLine(FreeVillagersInfo + freeVillagers + "".PadRight(freeVillagers.ToString().Length) + "\n");
uint assignedVillagers = totalVillagers - freeVillagers;
Console.WriteLine(AssignedVillagersInfo + assignedVillagers + "".PadRight(assignedVillagers.ToString().Length));
for (int i = 1; i <= options.Length; i++)
{
Console.Write((selectedOption == i ? ActiveOption : InactiveOption) + fisherList[i - 1] + AssignedOptionInfo +
options[i - 1] + " (" + fishList[i - 1].GetCatchDifficultyString() + " difficulty)" +
"".PadRight(fisherList[i - 1].ToString().Length) + "\n");
}
ConsoleKey key = Console.ReadKey(true).Key;
Console.SetCursorPosition(0, Console.CursorTop - options.Length - 3);
Console.CursorVisible = false;
switch (key)
{
case ConsoleKey.UpArrow:
if (selectedOption > 1)
selectedOption--;
break;
case ConsoleKey.DownArrow:
if (selectedOption < options.Length)
selectedOption++;
break;
case ConsoleKey.LeftArrow:
if (fisherList[selectedOption - 1] > 0)
{
fisherList[selectedOption - 1]--;
freeVillagers++;
}
break;
case ConsoleKey.RightArrow:
ParseOption(selectedOption);
break;
case ConsoleKey.Enter:
ConfirmAssignment();
break;
case ConsoleKey.D1:
case ConsoleKey.D2:
case ConsoleKey.D3:
case ConsoleKey.D4:
case ConsoleKey.D5:
case ConsoleKey.D6:
case ConsoleKey.D7:
case ConsoleKey.D8:
case ConsoleKey.D9:
ParseOption((int)key - 48);
break;
case ConsoleKey.Escape:
ParseEscapeOption();
break;
}
}
Console.CursorVisible = true;
}
override public void ParseOption(int option)
{
if (options.Length < option)
return;
if (freeVillagers > 0)
{
fisherList[option - 1]++;
freeVillagers--;
}
}
override public void ParseEscapeOption()
{
confirmed = false;
continueDisplay = false;
Console.Clear();
Console.WriteLine("Assignment cancelled.");
}
public void ConfirmAssignment()
{
confirmed = true;
continueDisplay = false;
Console.Clear();
Console.WriteLine("Assignment confirmed.\n");
Console.WriteLine(AssignedVillagersInfo + (totalVillagers - freeVillagers));
for (int i = 1; i <= options.Length; i++)
Console.Write(fisherList[i - 1] + AssignedOptionInfo + options[i - 1] + ".\n");
Console.WriteLine("\n");
}
public List<uint> GetFisherList(List<uint> existingFishers)
{
return confirmed ? fisherList : existingFishers;
}
}
}