-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameEngine.cs
105 lines (92 loc) · 5.65 KB
/
GameEngine.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Game
{
class GameEngine
{
// initialize the NPCs and important vars
public Player mainPlayer = new Player();
public BadGuy BadGuy1 = new BadGuy();
public Medic Medic1 = new Medic();
public Mines Mine1 = new Mines();
int x;
int y;
Loc exitPoint = new Loc();
Map map = new Map();
public GameEngine() { }
// default constructor defining the boundaries
public GameEngine(int X, int Y, Loc exit)
{
x = X;
y = Y;
exitPoint = exit;
}
// getter for MC
public Player GetPlayer()
{
return mainPlayer;
}
// initialize the map and draw it
public void Init()
{
map = new Map(x, y, exitPoint);
map.Draw(mainPlayer, BadGuy1, Medic1, Mine1);
}
public string endScreen = "┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n███▀▀▀██┼███▀▀▀███┼███▀█▄█▀███┼██▀▀▀\n██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼█┼┼┼██┼██┼┼┼\n██┼┼┼▄▄▄┼██▄▄▄▄▄██┼██┼┼┼▀┼┼┼██┼██▀▀▀\n██┼┼┼┼██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██┼┼┼\n███▄▄▄██┼██┼┼┼┼┼██┼██┼┼┼┼┼┼┼██┼██▄▄▄\n┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n███▀▀▀███┼▀███┼┼██▀┼██▀▀▀┼██▀▀▀▀██▄┼\n██┼┼┼┼┼██┼┼┼██┼┼██┼┼██┼┼┼┼██┼┼┼┼┼██┼\n██┼┼┼┼┼██┼┼┼██┼┼██┼┼██▀▀▀┼██▄▄▄▄▄▀▀┼\n██┼┼┼┼┼██┼┼┼██┼┼█▀┼┼██┼┼┼┼██┼┼┼┼┼██┼\n███▄▄▄███┼┼┼─▀█▀┼┼─┼██▄▄▄┼██┼┼┼┼┼██▄\n┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼██┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼██┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼████▄┼┼┼▄▄▄▄▄▄▄┼┼┼▄████┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼▀▀█▄█████████▄█▀▀┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼┼┼█████████████┼┼┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼┼┼██▀▀▀███▀▀▀██┼┼┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼┼┼██┼┼┼███┼┼┼██┼┼┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼┼┼█████▀▄▀█████┼┼┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼┼┼┼███████████┼┼┼┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼▄▄▄██┼┼█▀█▀█┼┼██▄▄▄┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼▀▀██┼┼┼┼┼┼┼┼┼┼┼██▀▀┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼┼▀▀┼┼┼┼┼┼┼┼┼┼┼▀▀┼┼┼┼┼┼┼┼┼┼┼\n┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\n";
// function to print the end game screen
void printEnd()
{
Console.WriteLine(endScreen + "\n\n");
Console.WriteLine("Press <Enter> to exit... ");
}
// function to check for events
// such as if they die, or reach the exit
// or if they touch an NPC
public void CheckEvents()
{
// if reached a end condition
if (EndCondition(mainPlayer))
{
Console.Clear();
printEnd();
Console.WriteLine();
while (Console.ReadKey().Key != ConsoleKey.Enter) { }
Environment.Exit(0);
}
// when touching a BadGuy
if (mainPlayer.location == BadGuy1.UpdateLocation())
{
Console.WriteLine("BADGUY HAPPENED");
BadGuy1.Action(mainPlayer);
}
// when touching a Medic
if (mainPlayer.location == Medic1.UpdateLocation())
{
Console.WriteLine("MEDIC HAPPENED");
Medic1.Action(mainPlayer);
}
// when touching a Mine
if (mainPlayer.location == Mine1.UpdateLocation())
{
Console.WriteLine("ON A MINE HAPPENED");
Mine1.Action(mainPlayer);
}
// Draw the map after performing actions
map.Draw(mainPlayer, BadGuy1, Medic1, Mine1);
}
// define the end condition as either reaching checkpoint or having HP below 0
public bool EndCondition(Player mainPlayer)
{
if (mainPlayer.health < 1)
return true;
if (mainPlayer.location == map.GetExit())
{
return true;
}
return false;
}
}
}