-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cs
524 lines (502 loc) · 22.6 KB
/
Game.cs
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
using System;
using System.Collections.Generic;
namespace ttc_wtc
{
class Game
{
public enum Status
{
ClassMenu = 0,
Closed = 1,
InGame = 2,
PauseMenu = 3,
StartMenu = 4,
Inventory = 5,
SlotChoice = 6,
ItemChoice = 7,
ChestOpened = 8,
CheatConsole = 9,
InBattle = 10,
InBattleForEntity = 11,
InNPC = 12,
InDialog = 13,
Theft = 14
}
public Player player;
public List<Entity> entities;
public List<Chest> chests;
public NPC CurrentNPC { get; set; }
public bool mainQuestIsActive = true;
public bool supQestisActive = true;
public static Status GameStatus { get; set; }
public Game(Player player, List<Entity> entities = null, List<Chest> chests = null)
{
this.player = player;
this.entities = entities;
this.chests = chests;
}
public static void StartNewGame(bool endless = false, Status status = Status.StartMenu)
{
Program.CurrentGame = new Game(Program.GenerateStartPlayer(endless), endless ? null : Program.GenerateStartEntities(), endless ? null : Program.GenerateStartChests());
GameStatus = status;
Program.CurrentGame.Start(endless);
}
public static void StartGame(Player player, List<Entity> entities, List<Chest> chests, bool endless)
{
Program.CurrentGame = new Game(player, entities, chests);
GameStatus = Status.InGame;
Program.CurrentGame.Start(endless, false);
}
public static void GetStartMenuChoice()
{
bool gameStart = false; ;
while (!gameStart)
{
int choice = Menu.StartMenu.GetChoice();
switch (choice)
{
case 0:
gameStart = true;
StartNewGame(false, Status.ClassMenu);
break;
case 1:
gameStart = true;
StartNewGame(true, Status.ClassMenu);
break;
case 2:
Player player = new Player();
List<Entity> entities = new List<Entity>();
List<Chest> chests = new List<Chest>();
if (SaveAndLoad.Load(ref player, ref entities, ref chests, out bool? endless))
{
gameStart = true;
StartGame(player, entities, chests, (bool)endless);
}
else
{
gameStart = false;
}
break;
case 3:
Environment.Exit(0);
break;
}
}
}
public void Start(bool endless = false, bool initialise = true)
{
if (!endless)
{
if (initialise)
{
CollectedMaps.Initialise();
}
foreach (Entity entity in entities)
{
CollectedMaps.SetEntity(entity.MapId, entity.X, entity.Y, entity);
}
foreach (Chest chest in chests)
{
CollectedMaps.SetChest(chest.MapId, chest.X, chest.Y, chest);
}
}
else if (initialise)
{
CollectedMaps.EndlessInitialise();
}
CollectedMaps.SetEntity(player.MapId, player.X, player.Y, player);
Draw.CurrentMapId = player.MapId;
int moveX = 0;
int moveY = 0;
do
{
if (player.Have("Ключ от старых ворот") && supQestisActive)
{
player.QuestNumber = 2;
CollectedMaps.InitialiseClosedDour(0);
supQestisActive = false;
}
switch (GameStatus)
{
case Status.InGame:
InGameStatus(out moveX, out moveY, endless);
break;
case Status.ClassMenu:
TarotMenuStatus(endless);
break;
case Status.Inventory:
InventoryStatus(endless);
break;
case Status.ChestOpened:
ChestStatus(moveX, moveY, endless);
break;
case Status.InNPC:
NPCStatus(moveX, moveY);
break;
case Status.InBattle:
BattleStatus(endless);
break;
case Status.PauseMenu:
PauseStatus(endless);
break;
case Status.CheatConsole:
ConsoleStatus(endless);
break;
case Status.InDialog:
InDialog(moveX, moveY, endless);
break;
case Status.Theft:
InTheft(moveX, moveY);
break;
case Status.Closed:
Environment.Exit(0);
break;
}
} while (true);
}
public void NPCStatus(int moveX, int moveY)
{
int choice = Menu.NPCMenu.GetChoice();
switch (choice)
{
case 0:
GameStatus = Status.InDialog;
break;
case 2:
CurrentNPC = (NPC)CollectedMaps.GetEntity(player.MapId, player.X + moveX, player.Y + moveY);
player.AddItems(CollectedMaps.GetAllItemsFromNPC(player.MapId, player.X + moveX, player.Y + moveY));
CurrentNPC = new Enemy(CurrentNPC.Name, CurrentNPC.HP.MaximumHP, CurrentNPC.Damage.CurrentDamage,
CurrentNPC.Defense.CurrentDefense, CurrentNPC.MapId, CurrentNPC.X, y: CurrentNPC.Y);
CollectedMaps.SetEntity(CurrentNPC.MapId, CurrentNPC.X, CurrentNPC.Y, CurrentNPC);
GameStatus = Status.InBattle;
break;
case 1:
GameStatus = Status.Theft;
break;
case 3:
GameStatus = Status.InGame;
break;
}
}
public void InDialog(int moveX, int moveY, bool endlessGame = false)
{
Console.Clear();
CurrentNPC = (NPC)CollectedMaps.GetEntity(player.MapId, player.X + moveX, player.Y + moveY);
Quest.QestChecking(player, CurrentNPC, entities[0]);
if (CurrentNPC.Dialog.GetDialog(CurrentNPC) == 0)
{
if (CurrentNPC.Dialog.Completeness && CurrentNPC.Name == "Эрика")
{
player.QuestNumber = 1;
}
GameStatus = Status.InGame;
}
else
{
player.AddItems(CollectedMaps.GetAllItemsFromNPC(player.MapId, player.X + moveX, player.Y + moveY));
CurrentNPC = new Enemy(CurrentNPC.Name, CurrentNPC.HP.MaximumHP, CurrentNPC.Damage.CurrentDamage,
CurrentNPC.Defense.CurrentDefense, CurrentNPC.MapId, CurrentNPC.X, y: CurrentNPC.Y);
CollectedMaps.SetEntity(CurrentNPC.MapId, CurrentNPC.X, CurrentNPC.Y, CurrentNPC);
GameStatus = Status.InBattle;
}
}
public void InTheft(int moveX, int moveY)
{
CurrentNPC = (NPC)CollectedMaps.GetEntity(player.MapId, player.X + moveX, player.Y + moveY);
Menu TiefsMenu = new Menu(CurrentNPC.GetTiefsItemNames());
int theftChoice = TiefsMenu.GetChoice(true, true);
if (theftChoice == CurrentNPC.GetTiefsItemNames().Count - 1)
{
GameStatus = Status.InGame;
}
else if (theftChoice < CurrentNPC.GetTiefsItemNames().Count - 2)
{
if (new Random().Next(0, 2) == 1)
{
player.AddItem(CollectedMaps.GetItemFromNPC(player.MapId, player.X + moveX, player.Y + moveY, theftChoice));
GameStatus = Status.InGame;
}
else
{
player.AddItems(CollectedMaps.GetAllItemsFromNPC(player.MapId, player.X + moveX, player.Y + moveY));
CurrentNPC = new Enemy(CurrentNPC.Name, CurrentNPC.HP.MaximumHP, CurrentNPC.Damage.CurrentDamage,
CurrentNPC.Defense.CurrentDefense, CurrentNPC.MapId, CurrentNPC.X, y: CurrentNPC.Y);
CollectedMaps.SetEntity(CurrentNPC.MapId, CurrentNPC.X, CurrentNPC.Y, CurrentNPC);
GameStatus = Status.InBattle;
}
}
else if (theftChoice == CurrentNPC.GetTiefsItemNames().Count - 2)
{
if (new Random().Next(0, CurrentNPC.NPCInventory.Count) == 1)
{
player.AddItems(CollectedMaps.GetAllItemsFromNPC(player.MapId, player.X + moveX, player.Y + moveY));
GameStatus = Status.InGame;
}
else
{
player.AddItems(CollectedMaps.GetAllItemsFromNPC(player.MapId, player.X + moveX, player.Y + moveY));
CurrentNPC = new Enemy(CurrentNPC.Name, CurrentNPC.HP.MaximumHP, CurrentNPC.Damage.CurrentDamage,
CurrentNPC.Defense.CurrentDefense, CurrentNPC.MapId, CurrentNPC.X, y: CurrentNPC.Y);
CollectedMaps.SetEntity(CurrentNPC.MapId, CurrentNPC.X, CurrentNPC.Y, CurrentNPC);
GameStatus = Status.InBattle;
}
}
}
public void TarotMenuStatus(bool endlessGame = false)
{
int choice = Menu.TarotMenu.GetChoice();
player.SelectTarot(choice);
GameStatus = Status.InGame;
}
public void InGameStatus(out int moveX, out int moveY, bool endlessGame = false)
{
Draw.ReDrawMap(CollectedMaps.GetDrawnMap(player.MapId), player.MapId);
do
{
moveX = 0;
moveY = 0;
Draw.DrawMapInterface(player, 53, 3, endlessGame);
switch (Console.ReadKey(true).Key)
{
case ConsoleKey.Escape:
GameStatus = Status.PauseMenu;
break;
case ConsoleKey.C:
GameStatus = Status.CheatConsole;
break;
case ConsoleKey.I:
GameStatus = Status.Inventory;
break;
case ConsoleKey.W:
moveY = -1;
break;
case ConsoleKey.A:
moveX = -1;
break;
case ConsoleKey.S:
moveY = 1;
break;
case ConsoleKey.D:
moveX = 1;
break;
}
if (((moveX != 0) || (moveY != 0)) && (player.Move(moveX, moveY, endlessGame)))
{
CollectedMaps.EnemyMovement(player.MapId, player.X, player.Y);
}
if (entities != null && !entities[0].Alive && mainQuestIsActive && entities[1].Alive)
{
player.QuestNumber = 3;
Draw.ReDrawMap(CollectedMaps.GetDrawnMap(player.MapId), player.MapId);
NPC vilianNPC = (NPC)CollectedMaps.GetEntity(entities[1].MapId, entities[1].X, entities[1].Y);
if (vilianNPC.Have("Статуэтка чайки"))
{
vilianNPC.HP = (6000, 6000);
vilianNPC.Damage = (500, 500);
vilianNPC.Defense = (50, 50);
mainQuestIsActive = false;
entities.RemoveAt(1);
CollectedMaps.DelEntity(vilianNPC.MapId, vilianNPC.X, vilianNPC.Y);
vilianNPC = new Enemy(vilianNPC.Name, vilianNPC.HP.MaximumHP, vilianNPC.Damage.CurrentDamage,
vilianNPC.Defense.CurrentDefense, vilianNPC.MapId, vilianNPC.X, y: vilianNPC.Y);
entities.Add(vilianNPC);
CollectedMaps.SetEntity(vilianNPC.MapId, vilianNPC.X, vilianNPC.Y, vilianNPC);
}
else
{
mainQuestIsActive = false;
entities.RemoveAt(1);
CollectedMaps.DelEntity(vilianNPC.MapId, vilianNPC.X, vilianNPC.Y);
vilianNPC = new Enemy(vilianNPC.Name, vilianNPC.HP.MaximumHP, vilianNPC.Damage.CurrentDamage,
vilianNPC.Defense.CurrentDefense, vilianNPC.MapId, vilianNPC.X, y: vilianNPC.Y);
entities.Add(vilianNPC);
CollectedMaps.SetEntity(vilianNPC.MapId, vilianNPC.X, vilianNPC.Y, vilianNPC);
}
CollectedMaps.EnemyMovement(player.MapId, player.X, player.Y);
}
} while (GameStatus == Status.InGame);
}
public void InventoryStatus(bool endlessGame = false)
{
do
{
List<string> inventoryItems = player.GetInventorySlotNames();
Menu inventoryMenu = new Menu(inventoryItems);
int inventoryChoice = inventoryMenu.GetChoice();
if (inventoryChoice == inventoryItems.Count - 1)
{
GameStatus = Status.InGame;
player.CountStatsByItems();
break;
}
Menu slotMenu = new Menu(player.GetNamesBySlot(inventoryChoice));
int slotChoice = slotMenu.GetChoice();
if (slotChoice == 0)
{
if (inventoryChoice != inventoryItems.Count - 2 && inventoryChoice != Consumable.ConsumableSlot)
{
player.EquippedItems[inventoryChoice] = null;
}
}
else
{
player.ChangeItemByChoice(slotChoice, inventoryChoice);
}
} while (true);
}
public void ChestStatus(int moveX, int moveY, bool endlessGame = false)
{
string[] chestMenuItems = CollectedMaps.GetChestItems(player.MapId, player.X + moveX, player.Y + moveY);
Menu chestMenu = new Menu(chestMenuItems);
int choice = chestMenu.GetChoice();
if (choice < chestMenuItems.Length - 2)
{
player.AddItem(CollectedMaps.GetItemFromChest(player.MapId, player.X + moveX, player.Y + moveY, choice));
}
else if (choice == chestMenuItems.Length - 2)
{
player.AddItems(CollectedMaps.GetAllItemsFromChest(player.MapId, player.X + moveX, player.Y + moveY));
}
GameStatus = Status.InGame;
if (CollectedMaps.GetChestItems(player.MapId, player.X + moveX, player.Y + moveY).Length == 1)
{
CollectedMaps.DelChest(player.MapId, player.X + moveX, player.Y + moveY);
}
}
public void BattleStatus(bool endlessGame = false)
{
Battle currentBattle = new Battle(player, CollectedMaps.GetNearEnemies(player.MapId, player.X, player.Y));
currentBattle.Start();
}
public void PauseStatus(bool endlessGame = false)
{
int choice = Menu.PauseMenu.GetChoice();
switch (choice)
{
case 0:
GameStatus = Status.InGame;
break;
case 1:
SaveAndLoad.Save(player, entities, chests, endlessGame);
break;
case 2:
if (SaveAndLoad.Load(ref player, ref entities, ref chests, out bool? endless))
{
StartGame(player, entities, chests, (bool)endless);
}
break;
case 3:
GetStartMenuChoice();
break;
}
}
public void ConsoleStatus(bool endlessGame = false)
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Введите команду: ");
Console.CursorVisible = true;
while (GameStatus == Status.CheatConsole)
{
string input = Console.ReadLine();
string[] strings = input.Split(' ');
switch (strings.Length)
{
case 0:
case 1:
switch (strings[0])
{
case "help":
Console.WriteLine("help - список команд \n" +
"kill - убить игрока \n" +
"restart - запустить игру с самого начала \n" +
"exit - выйти из консоли \n" +
"closeapp - выйти из игры \n" +
"give {id} - получить предмет по id \n" +
"set {stat} {number} - изменить значение данной характеристики");
break;
case "kill":
Console.ResetColor();
Console.CursorVisible = false;
StartNewGame(endlessGame);
break;
case "restart":
Console.ResetColor();
Console.CursorVisible = false;
StartNewGame(endlessGame, Status.ClassMenu);
break;
case "exit":
Console.ResetColor();
Console.CursorVisible = false;
GameStatus = Status.InGame;
break;
case "closeapp":
Environment.Exit(0);
break;
default:
Console.WriteLine("Неизвестная команда. Введите help для просмотра списка команд.");
break;
}
break;
case 2:
switch (strings[0])
{
case "give":
if (int.TryParse(strings[1], out int id) && id >= 0 && id < Item.Items.Count)
{
player.AddItem(Item.Items[id]);
Console.WriteLine("Успешно.");
}
else Console.WriteLine("Неверный id предмета. введите целое число от 0 до {0}.", Item.Items.Count - 1);
break;
default:
Console.WriteLine("Неизвестная команда. Введите help для просмотра списка команд.");
break;
}
break;
case 3:
if (strings[0] == "set")
{
bool error = true;
int value;
switch (strings[1])
{
case "hp":
if (int.TryParse(strings[2], out value) && value > 0)
{
player.HP = (value, player.HP.MaximumHP > value ? player.HP.MaximumHP : value);
error = false;
Console.WriteLine("Успешно.");
}
break;
case "damage":
if (int.TryParse(strings[2], out value) && value > 0)
{
player.Damage = (value, value);
error = false;
Console.WriteLine("Успешно.");
}
break;
case "defense":
if (int.TryParse(strings[2], out value) && value > 0)
{
player.Defense = (value, value);
error = false;
Console.WriteLine("Успешно.");
}
break;
default:
break;
}
if (error)
{
Console.WriteLine("Произошла ошибка. Проверьте правильность данных.");
}
}
else Console.WriteLine("Неизвестная команда. Введите help для просмотра списка команд.");
break;
}
}
}
}
}