-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cs
75 lines (65 loc) · 2.33 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
using System;
using System.Reflection;
namespace Game
{
public class Game
{
Loc exitPoint = new Loc();
GameEngine engine = new GameEngine();
void loadExtensions()
{
// extension logic
var DLL = Assembly.LoadFile(@"C:\Users\gatesyp\Documents\Visual Studio 2015\Projects\Game\Game\Extensions\EndScreen.dll");
var class1Type = DLL.GetType("Game.EndScreenExtension");
dynamic c = Activator.CreateInstance(class1Type);
string end = c.GetEnding();
engine.endScreen = end;
}
public Game(int param)
{
Console.Clear();
// load players and objects
exitPoint.Is(0, 0);
// create the engine with initial inputs
engine = new GameEngine(30, 30, exitPoint);
engine.Init();
// if param is 48 (number assigned to key '0'), start game w/ extensions
// else, vanilla game is created
if (param == 48)
loadExtensions();
var mainPlayer = engine.GetPlayer();
}
// will start the game loop
public void Loop()
{
// game loop starts here. calls for event checks from engine and moves the player according to key presses
for (;;)
{
if (Console.KeyAvailable)
{
var key = Console.ReadKey().Key;
if (key == ConsoleKey.UpArrow)
{
engine.mainPlayer.Up();
engine.CheckEvents();
}
if (key == ConsoleKey.DownArrow)
{
engine.mainPlayer.Down();
engine.CheckEvents();
}
if (key == ConsoleKey.LeftArrow)
{
engine.mainPlayer.Left();
engine.CheckEvents();
}
if (key == ConsoleKey.RightArrow)
{
engine.mainPlayer.Right();
engine.CheckEvents();
}
}
}
}
}
}