/
TestRoom.cs
90 lines (75 loc) · 2.28 KB
/
TestRoom.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
// <copyright file="TestRoom.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>
namespace Adventure.Test
{
using System.Collections.Generic;
public sealed class TestRoom : Room
{
private readonly string color;
public TestRoom(MessageBus bus, string color = null)
: base(bus)
{
this.color = color;
}
protected override string Description
{
get
{
List<string> parts = new List<string>();
parts.Add("You are in a");
if (this.color != null)
{
parts.Add(this.color);
}
parts.Add("test room.");
return string.Join(" ", parts);
}
}
public void TestRegisterHello(string verb)
{
this.Register(verb, this.Hello);
}
protected override void EnterCore()
{
this.TestRegisterHello("hello");
this.Register("look", (_, n) => this.Look(n));
this.Register("take", this.Take);
this.Register("inventory", (_, __) => this.Inventory());
this.Register("drop", this.Drop);
this.Register("go", this.Go);
this.Register("quit", (_, __) => this.End("You quit. Game over."));
}
protected override bool LookAtCore(Word noun)
{
if (noun.Primary == "up")
{
this.Output("You see the ceiling.");
return true;
}
return base.LookAtCore(noun);
}
protected override bool TakeCore(Word noun)
{
if (noun.Primary == "breath")
{
this.Output("You inhale deeply.");
return true;
}
return base.TakeCore(noun);
}
protected override bool GoCore(Word noun)
{
if (noun.Primary == "fish")
{
this.Output("This is no time to play cards.");
return true;
}
return base.GoCore(noun);
}
private void Hello(Word verb, Word noun)
{
this.Output("Hello, " + noun + "!");
}
}
}