Skip to content
Permalink
Browse files

Room - DropOneItem

  • Loading branch information...
bobbymcr committed Dec 14, 2018
1 parent 1d3b2b6 commit fcc87d78c170be0e3d0b50ab3205ed4be827f0cf
Showing with 49 additions and 0 deletions.
  1. +22 −0 core/src/InventoryDropMessage.cs
  2. +5 −0 core/src/Room.cs
  3. +21 −0 core/test/RoomTest.cs
  4. +1 −0 core/test/TestRoom.cs
@@ -0,0 +1,22 @@
// <copyright file="InventoryDropMessage.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure
{
public sealed class InventoryDropMessage
{
public InventoryDropMessage(Items items, Word verb, Word noun)
{
this.Items = items;
this.Verb = verb;
this.Noun = noun;
}

public Items Items { get; }

public Word Verb { get; }

public Word Noun { get; }
}
}
@@ -96,6 +96,11 @@ protected virtual bool LookAtCore(Word noun)
return false;
}

protected void Drop(Word verb, Word noun)
{
this.bus.Send(new InventoryDropMessage(this.items, verb, noun));
}

protected void Take(Word verb, Word noun)
{
if (noun.Actual.Length == 0)
@@ -266,6 +266,27 @@ public void ProcessUnknownVerb()
"You can't do that.");
}

[Fact]
public void DropOneItem()
{
MessageBus bus = new MessageBus();
Dictionary<string, Item> items = new Dictionary<string, Item>();
items["DROP/KEY"] = new TestKey();
bus.Subscribe<InventoryDropMessage>(m => m.Items.Add(m.Noun.Primary, items[$"{m.Verb}/{m.Noun}"]));
List<string> output = new List<string>();
bus.Subscribe<OutputMessage>(m => output.Add(m.Text));
TestRoom room = new TestRoom(bus);

room.Enter();
bus.Send(new SentenceMessage(new Word("drop", "DROP"), new Word("key", "KEY")));
bus.Send(new SentenceMessage(new Word("look", "LOOK"), new Word(string.Empty, string.Empty)));

output.Should().Equal(
"You are in a test room.",
"You are in a test room.",
"There is a key here.");
}

[Fact]
public void AddOneItem()
{
@@ -44,6 +44,7 @@ protected override void EnterCore()
this.Register("look", (_, n) => this.Look(n));
this.Register("take", this.Take);
this.Register("inventory", (_, __) => this.Inventory());
this.Register("drop", this.Drop);
}

protected override bool LookAtCore(Word noun)

0 comments on commit fcc87d7

Please sign in to comment.
You can’t perform that action at this time.