Skip to content
This repository has been archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from sdphp/master
Browse files Browse the repository at this point in the history
pulling new changes form sdphp:master
  • Loading branch information
OneCodingMonkey committed Dec 13, 2014
2 parents e614ebc + f3dde39 commit 704ca94
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 235 deletions.
2 changes: 1 addition & 1 deletion app/game
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ $delegatingLoader = new DelegatingLoader($loaderResolver);

$gameDice = new BasicDice();
$gameLogic = new BasicGameLogic();
$gameState = new BasicGameState($gameDice);
$player = new BasicPlayer($delegatingLoader);
$gameState = new BasicGameState($player, $gameDice, ['position' => 0]);
$gameState->setPlayer($player);

// <====
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"php": ">=5.4",
"symfony/console": "~2.6",
"symfony/yaml": "~2.6",
"symfony/config": "~2.6"
"symfony/config": "~2.6",
"symfony/http-foundation": "~2.6"
},
"autoload": {
"psr-4": {
Expand Down
95 changes: 74 additions & 21 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions src/Command/GameCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use SDPHP\PHPMicrork\IO\GameCLIIO;
use SDPHP\PHPMicrork\Logic\GameLogicInterface;
use SDPHP\PHPMicrork\Loop\GameLoop;
use SDPHP\PHPMicrork\State\GameStateInterface;
use SDPHP\PHPMicrork\State\StateInterface;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -42,7 +42,7 @@ class GameCommand extends Command
*/
private $gameLogic;

public function __construct(DelegatingLoader $delegatingLoader, GameStateInterface $gameState, GameLogicInterface $gameLogic, $name = null)
public function __construct(DelegatingLoader $delegatingLoader, StateInterface $gameState, GameLogicInterface $gameLogic, $name = null)
{
parent::__construct($name);
$this->delegatingLoader = $delegatingLoader;
Expand All @@ -53,7 +53,7 @@ public function __construct(DelegatingLoader $delegatingLoader, GameStateInterfa
protected function configure()
{
$this
->setName('micrork:run')
->setName('run')
->setDescription('Main command to start a new PHPOrk game.')
->addArgument(
'name',
Expand Down Expand Up @@ -85,16 +85,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$gameIO = new GameCLIIO($questionHelper, $input, $output);
$gameLoop = new GameLoop($gameIO);
$this->gameState->getPlayer()->setName($name);
$next = true;

while ($next !== false) {
$this->gameState->setLevel( $this->currentLevel['level']);
while (!$this->gameState->isStateOver()) {
$this->gameState->setProperty('level', $this->currentLevel['level']);
$gameLoop->start($this->gameState, $this->gameLogic);

if ($this->gameState->isGameOver()) {
$next = false;
} elseif ($this->gameState->isLevelOver()) {
$next = $this->gameState->getNextLevel();
$next = $this->gameState->getProperty('next_level', false);
if ($next) {
$this->loadLevel($next);
}
}
Expand Down
23 changes: 13 additions & 10 deletions src/Logic/BasicGameLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

use SDPHP\PHPMicrork\IO\GameIOInterface;
use SDPHP\PHPMicrork\Loop\FightLoop;
use SDPHP\PHPMicrork\State\GameStateInterface;
use SDPHP\PHPMicrork\Player\BasicNPC;
use SDPHP\PHPMicrork\State\StateInterface;

/**
* BasicGameLogic - Description.
Expand All @@ -18,12 +19,14 @@
*/
class BasicGameLogic implements GameLogicInterface
{
public function switchState(GameStateInterface $gameState, GameIOInterface $gameIO)
public function switchState(StateInterface $gameState, GameIOInterface $gameIO)
{
$room = $gameState->getRoom();
$location = $gameState->getProperty('location');
$locationProperty = sprintf('level[room][%s]', $location);
$room = $gameState->getProperty($locationProperty);
$directions = $room['directions'];
$gameIO->printPlace($room);

$gameIO->printPlace($room);
$input = $gameIO->askQuestion('Choose your next move: ');

// get command an argument, usually a verb followed by noun
Expand All @@ -34,31 +37,31 @@ public function switchState(GameStateInterface $gameState, GameIOInterface $game
switch(strtolower($command)) {
case 'north':
if (isset($directions[$command]) && $directions[$command] !== '-') {
$gameState->setPosition($directions[$command]);
$gameState->setProperty('location', $directions[$command]);
} else {
$gameIO->printError("You cannot go north!");
}
break;

case 'south':
if (isset($directions[$command]) && $directions[$command] !== '-') {
$gameState->setPosition($directions[$command]);
$gameState->setProperty('location', $directions[$command]);
} else {
$gameIO->printError("You cannot go south!");
}
break;

case 'west':
if (isset($directions[$command]) && $directions[$command] !=='-') {
$gameState->setPosition($directions[$command]);
$gameState->setProperty('location', $directions[$command]);
} else {
$gameIO->printError("You cannot go west!");
}
break;

case 'east':
if (isset($directions[$command]) && $directions[$command] !== '-') {
$gameState->setPosition($directions[$command]);
$gameState->setProperty('location', $directions[$command]);
} else {
$gameIO->printError("You cannot go east!");
}
Expand All @@ -70,7 +73,7 @@ public function switchState(GameStateInterface $gameState, GameIOInterface $game

case 'fight':
if ($argument) {
$gameState->loadNPC($argument);
$gameState->setNpc(new BasicNPC($argument));
$fightLoop = new FightLoop($gameIO);
$fightLoop->start($gameState, new FightLogic());

Expand All @@ -92,7 +95,7 @@ public function switchState(GameStateInterface $gameState, GameIOInterface $game
if ($argument) {
$gameIO->printComment(sprintf('Drinking %s, glup...', $argument));
if ($argument === 'water') {
$gameIO->printComment('Sissy!');
$gameIO->printComment('You hear a drunken warrion in the distance yell: "Sissy!"');
}
} else {
$gameIO->printError('You need to choose what you are Drinking');
Expand Down
8 changes: 5 additions & 3 deletions src/Logic/FightLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

namespace SDPHP\PHPMicrork\Logic;
use SDPHP\PHPMicrork\State\GameStateInterface;

use SDPHP\PHPMicrork\State\StateInterface;
use SDPHP\PHPMicrork\IO\GameIOInterface;


Expand All @@ -19,10 +20,11 @@
class FightLogic implements GameLogicInterface
{

public function switchState(GameStateInterface $state, GameIOInterface $gameIO)
public function switchState(StateInterface $state, GameIOInterface $gameIO)
{
$player = $state->getPlayer();
$npc = $state->getNPC();
$npc = $state->getNPCs();

// TODO: Implement switchState() method.
}
}
5 changes: 3 additions & 2 deletions src/Logic/GameLogicInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* please view the LICENSE file that was distributed
* with this source code.
*/

namespace SDPHP\PHPMicrork\Logic;

use SDPHP\PHPMicrork\IO\GameIOInterface;
use SDPHP\PHPMicrork\State\GameStateInterface;
use SDPHP\PHPMicrork\State\StateInterface;

/**
* LogicInterface - Description.
Expand All @@ -17,5 +18,5 @@
*/
interface GameLogicInterface
{
public function switchState(GameStateInterface $state, GameIOInterface $gameIO);
public function switchState(StateInterface $state, GameIOInterface $gameIO);
}
4 changes: 2 additions & 2 deletions src/Loop/AbstractGameLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use SDPHP\PHPMicrork\IO\GameIOInterface;
use SDPHP\PHPMicrork\Logic\GameLogicInterface;
use SDPHP\PHPMicrork\State\GameStateInterface;
use SDPHP\PHPMicrork\State\StateInterface;

/**
* AbstractGameLoopo - Description.
Expand All @@ -28,5 +28,5 @@ public function __construct(GameIOInterface $gameIO)
$this->gameIO = $gameIO;
}

abstract public function start(GameStateInterface $gameState, GameLogicInterface $gameLogic);
abstract public function start(StateInterface $gameState, GameLogicInterface $gameLogic);
}
Loading

0 comments on commit 704ca94

Please sign in to comment.