Skip to content

Commit

Permalink
Version8
Browse files Browse the repository at this point in the history
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 Jan 20, 2015
1 parent f68fd09 commit d125b4a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
6 changes: 5 additions & 1 deletion spec/Jenko/House/GardenSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
}
}
6 changes: 6 additions & 0 deletions spec/Jenko/House/HouseSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
6 changes: 5 additions & 1 deletion spec/Jenko/House/RoomSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();
}
}
16 changes: 16 additions & 0 deletions src/Jenko/House/House.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 6 additions & 1 deletion src/Jenko/House/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.