/
Core.cs
170 lines (146 loc) · 5.52 KB
/
Core.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
using System;
using System.Collections.Generic;
using GrammarLibrary;
using WorldModel;
namespace StandardLibrary
{
public class Core
{
private Grammar _grammar;
public WorldManager WorldManager { get; private set; }
public Player Player { get; private set; }
public Core(World world)
{
_grammar = new Grammar(world);
WorldManager = new WorldManager(world);
Player = WorldManager.InitializePlayer(Player);
// Standard actions
var standardPot = _grammar.Verb("pot").Adjective.Noun.In.Adjective.Noun.End;
var standardTake = _grammar.Verb("take/get/grab", Take).Noun.End;
var metaExamine = _grammar.Verb("examine/x/ex", Examine).Noun.End;
var standardGoInNoun = _grammar.Verb("go", GoInNoun).In.Noun.End;
var standardGoNorth = _grammar.Direction("north/n", GoNorth).End;
var standardGoNortheast = _grammar.Direction("northeast/ne", GoNortheast).End;
var standardGoEast = _grammar.Direction("east/e", GoEast).End;
var standardGoSoutheast = _grammar.Direction("southeast/se", GoSoutheast).End;
var standardGoSouth = _grammar.Direction("south/s", GoSouth).End;
var standardGoSouthwest = _grammar.Direction("southwest/sw", GoSouthwest).End;
var standardGoWest = _grammar.Direction("west/w", GoWest).End;
var standardGoNorthwest = _grammar.Direction("northwest/nw", GoNorthwest).End;
var standardGoIn = _grammar.Verb("in", GoIn).End;
var standardGoInPrep = _grammar.Verb("go", GoIn).In.End;
var standardGoOut = _grammar.Direction("out", GoOut).End;
var standardGoUp = _grammar.Direction("up/u", GoUp).End;
var standardGoDown = _grammar.Direction("down/d", GoDown).End;
var standardWait = _grammar.Verb("wait/z", Wait).End;
var standardHangOn = _grammar.Verb("hang", HangOn).On.Noun.End;
var standardWear = _grammar.Verb("wear", Wear).Noun.End;
var standardPutOn = _grammar.Verb("put", Wear).On.Noun.End;
// Meta actions
_grammar.MetaVerb("score", Score);
_grammar.MetaVerb("restore", Restore);
_grammar.MetaVerb("restart", Restart);
_grammar.MetaVerb("i/inventory", Inventory);
// Override the "go" action
var goInNoun = new List<Token>
{
new Token(TokenType.Verb, "go", GoIn, ActionType.Standard),
new Token(TokenType.Preposition, "in"),
new Token(TokenType.Noun)
};
_grammar.OverrideActionDelegate("go", goInNoun, CustomGo);
}
private void Take(List<Token>? tokens)
{
Console.WriteLine("You take the item.");
}
private void Examine(List<Token>? tokens)
{
Console.WriteLine("You examine the item.");
}
private void GoNorth(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoNortheast(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoEast(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoSoutheast(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoSouth(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoSouthwest(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoWest(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoNorthwest(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoInNoun(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoIn(List<Token>? tokens)
{
Console.WriteLine("You go somewhere.");
}
private void GoOut(List<Token>? tokens)
{
Console.WriteLine("You go in the thing.");
}
private void GoUp(List<Token>? tokens)
{
Console.WriteLine("You go in the thing.");
}
private void GoDown(List<Token>? tokens)
{
Console.WriteLine("You go in the thing.");
}
private void CustomGo(List<Token>? tokens)
{
Console.WriteLine("You go somewhere using a custom action.");
}
private void Wait(List<Token>? tokens)
{
Console.WriteLine("You contemplate the universe.");
}
private void HangOn(List<Token>? tokens)
{
Console.WriteLine("You contemplate the universe.");
}
private void Wear(List<Token>? tokens)
{
Console.WriteLine("You contemplate the universe.");
}
private void Inventory(List<Token>? tokens)
{
Console.WriteLine("Your score is 0.");
}
private void Score(List<Token>? tokens)
{
Console.WriteLine("Your score is 0.");
}
private void Restore(List<Token>? tokens)
{
Console.WriteLine("Game restored.");
}
private void Restart(List<Token>? tokens)
{
Console.WriteLine("Game restarted.");
}
}
}