Skip to content

Commit

Permalink
Game - add 'read' verb for Coin
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Dec 13, 2018
1 parent bd55ac4 commit c27ff5c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions sample/src/Coin.cs
Expand Up @@ -6,8 +6,39 @@ namespace Adventure.Sample
{
internal sealed class Coin : Item
{
private bool taken;

public override string ShortDescription => "a coin";

public override string LongDescription => "It is a small gold coin with an inscription on the edge.";

protected override bool TakeCore(MessageBus bus)
{
this.taken = true;
return base.TakeCore(bus);
}

protected override bool DoCore(MessageBus bus, Word verb, Word noun)
{
if (verb.Primary == Verb.Read)
{
this.Read(bus);
return true;
}

return base.DoCore(bus, verb, noun);
}

private void Read(MessageBus bus)
{
if (this.taken)
{
bus.Send(new OutputMessage("The inscription reads: \"MCMXCIX\""));
}
else
{
bus.Send(new OutputMessage("The writing is too small. You'd have to pick it up to see it better."));
}
}
}
}
1 change: 1 addition & 0 deletions sample/src/Game.cs
Expand Up @@ -37,6 +37,7 @@ private static Words InitializeWords()
w.Add(Verb.Look);
w.Add(Verb.Move);
w.Add(Verb.Quit, "exit");
w.Add(Verb.Read);
w.Add(Verb.Take, "get");
w.Add(Verb.Inventory, "inv");

Expand Down
1 change: 1 addition & 0 deletions sample/src/Verb.cs
Expand Up @@ -12,5 +12,6 @@ internal static class Verb
public const string Move = "move";
public const string Take = "take";
public const string Quit = "quit";
public const string Read = "read";
}
}
2 changes: 2 additions & 0 deletions sample/test/walkthrough.in
Expand Up @@ -14,7 +14,9 @@ look
look coin
get table
inv
read coin
GET COIN
read coin
inv
exit
-- END --
2 changes: 2 additions & 0 deletions sample/test/walkthrough.out
Expand Up @@ -19,7 +19,9 @@ There is a coin here.
> It is too heavy.
> You are carrying:
(nothing)
> The writing is too small. You'd have to pick it up to see it better.
> You GET the COIN.
> The inscription reads: "MCMXCIX"
> You are carrying:
a coin
>

0 comments on commit c27ff5c

Please sign in to comment.