Permalink
Browse files

Version8

Adding a way of exiting a room. Notice it's very similar to entering a
room but it's important that the language is maintained. We can tidy up
the code re-use later, although I like <a
href="http://verraes.net/2014/08/dry-is-about-knowledge/"
target="_blank">Mathias' definition of DRY</a>.
  • Loading branch information...
jenkoian committed Oct 6, 2014
1 parent f68fd09 commit d125b4a7f5e2ab55ce0910c7c4bd1d240d336f68
@@ -15,7 +15,6 @@ function let()
function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Garden');
$this->shouldHaveType('Jenko\House\Location');
}
function it_should_be_created_with_a_name()
@@ -24,4 +23,9 @@ function it_should_be_created_with_a_name()
$garden->shouldHaveType('Jenko\House\Garden');
$garden->getName()->shouldEqual('front garden');
}
function it_should_give_information()
{
$this->getInformation()->shouldBeArray();
}
}
@@ -55,4 +55,10 @@ function it_should_allow_entering_rooms()
$this->enterRoom('living room');
$this->whereAmI()->getName()->shouldBe('living room');
}
function it_should_allow_exiting_rooms()
{
$this->enterRoom('hallway');
$this->exitRoom('garden');
}
}
@@ -15,7 +15,6 @@ function let()
function it_is_initializable()
{
$this->shouldHaveType('Jenko\House\Room');
$this->shouldHaveType('Jenko\House\Location');
}
function it_should_be_created_with_a_name()
@@ -24,4 +23,9 @@ function it_should_be_created_with_a_name()
$garden->shouldHaveType('Jenko\House\Room');
$garden->getName()->shouldEqual('living room');
}
function it_should_give_an_array_of_information()
{
$this->getInformation()->shouldBeArray();
}
}
View
@@ -69,4 +69,20 @@ public function enterRoom($room)
$this->currentLocation = $room;
}
/**
* @param Location|string $room
*/
public function exitRoom($room)
{
if (!$room instanceof Location && is_string($room)) {
if (false !== strpos('garden', $room)) {
$room = Garden::named($room);
} else{
$room = Room::named($room);
}
}
$this->currentLocation = $room;
}
}
@@ -24,4 +24,9 @@ public function getName()
{
return $this->name;
}
}
public function getInformation()
{
return ['dimensions' => '', 'exits' => ''];
}
}

0 comments on commit d125b4a

Please sign in to comment.