Skip to content
Permalink
Browse files

Game - simplify Table logic using SendRoom

  • Loading branch information...
bobbymcr committed Dec 22, 2018
1 parent fc2d4a1 commit 7fc32581993be125c2ff27b7a27700e2187eb2e3
Showing with 6 additions and 6 deletions.
  1. +3 −0 core/src/Item.cs
  2. +1 −1 sample/src/MainRoom.cs
  3. +2 −5 sample/src/Table.cs
@@ -4,6 +4,7 @@

namespace Adventure
{
using System;
using Adventure.Messages;

public abstract class Item
@@ -46,5 +47,7 @@ public bool Drop()
protected virtual bool DropCore() => true;

protected void Output(string text) => this.Bus.Output(text);

protected void SendRoom(Action<Room> act) => this.Bus.Send(new RoomActionMessage(act));
}
}
@@ -9,7 +9,7 @@ internal sealed class MainRoom : RoomBase
public MainRoom(MessageBus bus)
: base(bus)
{
this.Add(Noun.Table, new Table(bus, this));
this.Add(Noun.Table, new Table(bus));
}

protected override string Description => "You are in the main room. There is a doorway to the east.";
@@ -6,14 +6,11 @@ namespace Adventure.Sample
{
internal sealed class Table : Item
{
private readonly Room parent;

private bool tableMoved;

public Table(MessageBus bus, Room parent)
public Table(MessageBus bus)
: base(bus)
{
this.parent = parent;
}

public override string ShortDescription => "a table";
@@ -43,7 +40,7 @@ private void Move()
{
this.tableMoved = true;
this.Output("You move the table slightly. Underneath you see a coin.");
this.parent.Add(Noun.Coin, new Coin(this.Bus));
this.SendRoom(r => r.Add(Noun.Coin, new Coin(this.Bus)));
}
else
{

0 comments on commit 7fc3258

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