-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
161 lines (146 loc) · 4.95 KB
/
Program.cs
File metadata and controls
161 lines (146 loc) · 4.95 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using TextEngine.Models;
using Microsoft.Data.Entity;
namespace TextEngine
{
class Program
{
public static Character character;
public static Random Random;
public static void RefreshGameState(TextEngineContext context)
{
character = Character.GetInstance(context);
if (character == null)
{
character = new Character();
character.SetInitialRoom(context);
context.Add(character);
context.SaveChanges();
}
}
static void Main(string[] args)
{
Program.Random = new Random();
// initialize database
using (var context = new TextEngineContext())
{
// TODO: remove this
//context.Database.EnsureDeleted();
if (context.Database.EnsureCreated())
{
context.Seed(context);
}
RefreshGameState(context);
}
Program.character.CurrentRoom.Look();
for (var play = true; play;)
{
Console.WriteLine();
Console.Write("[HP=" + Program.character.HP + "]> ");
string cmd = Console.ReadLine().Trim();
Console.WriteLine();
// split on one or more whitespace characters
var cmdParts = Regex.Split(cmd, @"\s+");
var action = cmdParts[0].ToLower();
var cmdArgs = cmdParts.Skip(1);
// on empty input, default to "look"
if (string.IsNullOrEmpty(action))
{
action = "l";
}
switch (action)
{
#if TEXTENGINEADMIN
case "create":
AdminCommands.Create(cmdParts);
break;
case "set":
AdminCommands.Set(cmdParts);
break;
case "list":
AdminCommands.ListMonsterTypes();
break;
case "spawn":
AdminCommands.SpawnMonster(cmdParts);
break;
case "give":
AdminCommands.Give(cmdParts);
break;
#endif
case "n":
case "north":
case "s":
case "south":
case "e":
case "east":
case "w":
case "west":
case "nw":
case "northwest":
case "ne":
case "northeast":
case "sw":
case "southwest":
case "se":
case "southeast":
case "u":
case "up":
case "d":
case "down":
character.CurrentRoom.Move(Utility.StringToDirection(action));
break;
case "l":
case "look":
PlayerCommands.Look(cmdParts);
break;
case "i":
case "inventory":
Program.character.Inventory.ShowInventory();
break;
case "g":
case "get":
case "t":
case "take":
PlayerCommands.Get(cmdParts);
break;
case "drop":
PlayerCommands.Drop(cmdParts);
break;
case "a":
case "attack":
PlayerCommands.Attack(cmdParts);
break;
case "q":
case "quit":
play = false;
break;
case "h":
case "help":
PlayerCommands.Help();
break;
case "m":
case "map":
PlayerCommands.DrawMap();
break;
default:
Console.WriteLine("I beg your pardon?");
break;
}
#if !TEXTENGINEADMIN
Utility.ProcessCombat();
#endif
if (Program.character.HP < 0)
{
Utility.Print(ConsoleColor.Red, "YOU HAVE DIED.");
play = false;
}
}
Console.WriteLine("Thanks for playing!");
}
}
}