Skip to content

Commit

Permalink
Item - make 'bus' protected property, remove arg from Do()
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbymcr committed Dec 15, 2018
1 parent a5d7fce commit b4f3611
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions core/src/Item.cs
Expand Up @@ -8,20 +8,20 @@ namespace Adventure

public abstract class Item
{
private readonly MessageBus bus;

protected Item(MessageBus bus)
{
this.bus = bus;
this.Bus = bus;
}

public abstract string ShortDescription { get; }

public abstract string LongDescription { get; }

public bool Do(MessageBus bus, Word verb, Word noun)
protected MessageBus Bus { get; }

public bool Do(Word verb, Word noun)
{
return this.DoCore(bus, verb, noun);
return this.DoCore(verb, noun);
}

public bool Take()
Expand All @@ -34,7 +34,7 @@ public bool Drop()
return this.DropCore();
}

protected virtual bool DoCore(MessageBus bus, Word verb, Word noun)
protected virtual bool DoCore(Word verb, Word noun)
{
return false;
}
Expand All @@ -51,7 +51,7 @@ protected virtual bool DropCore()

protected void Output(string text)
{
this.bus.Send(new OutputMessage(text));
this.Bus.Send(new OutputMessage(text));
}
}
}
2 changes: 1 addition & 1 deletion core/src/Items.cs
Expand Up @@ -91,7 +91,7 @@ private bool Do(SentenceMessage sentence)
{
if (this.items.TryGetValue(sentence.Noun.Primary, out Item item))
{
return item.Do(this.bus, sentence.Verb, sentence.Noun);
return item.Do(sentence.Verb, sentence.Noun);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions core/test/InventoryTest.cs
Expand Up @@ -299,11 +299,11 @@ public TestItem2(MessageBus bus)

public override string LongDescription => throw new System.NotImplementedException();

protected override bool DoCore(MessageBus bus, Word verb, Word noun)
protected override bool DoCore(Word verb, Word noun)
{
if (verb.Primary == "flip")
{
bus.Send(new OutputMessage($"You {verb} the {noun}; it lands on heads."));
this.Output($"You {verb} the {noun}; it lands on heads.");
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions core/test/ItemsTest.cs
Expand Up @@ -270,11 +270,11 @@ public TestItem(MessageBus bus)

public override string LongDescription => "It's a simple test item.";

protected override bool DoCore(MessageBus bus, Word verb, Word noun)
protected override bool DoCore(Word verb, Word noun)
{
if (verb.Primary == "throw")
{
bus.Send(new OutputMessage($"You threw the {noun}!"));
this.Output($"You threw the {noun}!");
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions core/test/RoomTest.cs
Expand Up @@ -486,11 +486,11 @@ public TestCoin(MessageBus bus)

public override string LongDescription => "It is a shiny new quarter.";

protected override bool DoCore(MessageBus bus, Word verb, Word noun)
protected override bool DoCore(Word verb, Word noun)
{
if (verb.Primary == "flip")
{
bus.Send(new OutputMessage($"You {verb} the {noun}; it lands on heads."));
this.Output($"You {verb} the {noun}; it lands on heads.");
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions sample/src/Coin.cs
Expand Up @@ -29,15 +29,15 @@ protected override bool DropCore()
return base.DropCore();
}

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

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

private void Read()
Expand Down
10 changes: 5 additions & 5 deletions sample/src/Table.cs
Expand Up @@ -26,24 +26,24 @@ protected override bool TakeCore()
return false;
}

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

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

private void Move(MessageBus bus)
private void Move()
{
if (!this.tableMoved)
{
this.tableMoved = true;
this.Output("You move the table slightly. Underneath you see a coin.");
this.parent.Add(Noun.Coin, new Coin(bus));
this.parent.Add(Noun.Coin, new Coin(this.Bus));
}
else
{
Expand Down

0 comments on commit b4f3611

Please sign in to comment.