Skip to content
Permalink
Browse files

Game - extract core room logic into RoomBase

  • Loading branch information...
bobbymcr committed Dec 16, 2018
1 parent 2a4f526 commit 3bc7974ed8946751a7c142f1f7e0b13292b4c844
Showing with 26 additions and 22 deletions.
  1. +1 −11 sample/src/AuxiliaryRoom.cs
  2. +1 −11 sample/src/MainRoom.cs
  3. +24 −0 sample/src/RoomBase.cs
@@ -4,23 +4,13 @@

namespace Adventure.Sample
{
internal sealed class AuxiliaryRoom : Room
internal sealed class AuxiliaryRoom : RoomBase
{
public AuxiliaryRoom(MessageBus bus)
: base(bus)
{
}

protected override string Description => "You are in the auxiliary room. There is a doorway to the west.";

protected override void EnterCore()
{
this.Register(Verb.Drop, this.Drop);
this.Register(Verb.Go, this.Go);
this.Register(Verb.Greet, (_, __) => this.Output("You say, \"Hello,\" to no one in particular. No one answers."));
this.Register(Verb.Look, (_, n) => this.Look(n));
this.Register(Verb.Inventory, (_, __) => this.Inventory());
this.Register(Verb.Take, this.Take);
}
}
}
@@ -4,7 +4,7 @@

namespace Adventure.Sample
{
internal sealed class MainRoom : Room
internal sealed class MainRoom : RoomBase
{
public MainRoom(MessageBus bus)
: base(bus)
@@ -13,15 +13,5 @@ public MainRoom(MessageBus bus)
}

protected override string Description => "You are in the main room. There is a doorway to the east.";

protected override void EnterCore()
{
this.Register(Verb.Drop, this.Drop);
this.Register(Verb.Go, this.Go);
this.Register(Verb.Greet, (_, __) => this.Output("You say, \"Hello,\" to no one in particular. No one answers."));
this.Register(Verb.Look, (_, n) => this.Look(n));
this.Register(Verb.Inventory, (_, __) => this.Inventory());
this.Register(Verb.Take, this.Take);
}
}
}
@@ -0,0 +1,24 @@
// <copyright file="RoomBase.cs" company="Brian Rogers">
// Copyright (c) Brian Rogers. All rights reserved.
// </copyright>

namespace Adventure.Sample
{
internal abstract class RoomBase : Room
{
protected RoomBase(MessageBus bus)
: base(bus)
{
}

protected override void EnterCore()
{
this.Register(Verb.Drop, this.Drop);
this.Register(Verb.Go, this.Go);
this.Register(Verb.Greet, (_, __) => this.Output("You say, \"Hello,\" to no one in particular. No one answers."));
this.Register(Verb.Look, (_, n) => this.Look(n));
this.Register(Verb.Inventory, (_, __) => this.Inventory());
this.Register(Verb.Take, this.Take);
}
}
}

0 comments on commit 3bc7974

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