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

Commit 704ca94

Browse files
Merge pull request #1 from sdphp/master
pulling new changes form sdphp:master
2 parents e614ebc + f3dde39 commit 704ca94

12 files changed

Lines changed: 217 additions & 235 deletions

app/game

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ $delegatingLoader = new DelegatingLoader($loaderResolver);
2424

2525
$gameDice = new BasicDice();
2626
$gameLogic = new BasicGameLogic();
27-
$gameState = new BasicGameState($gameDice);
2827
$player = new BasicPlayer($delegatingLoader);
28+
$gameState = new BasicGameState($player, $gameDice, ['position' => 0]);
2929
$gameState->setPlayer($player);
3030

3131
// <====

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"php": ">=5.4",
1616
"symfony/console": "~2.6",
1717
"symfony/yaml": "~2.6",
18-
"symfony/config": "~2.6"
18+
"symfony/config": "~2.6",
19+
"symfony/http-foundation": "~2.6"
1920
},
2021
"autoload": {
2122
"psr-4": {

composer.lock

Lines changed: 74 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Command/GameCommand.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use SDPHP\PHPMicrork\IO\GameCLIIO;
1212
use SDPHP\PHPMicrork\Logic\GameLogicInterface;
1313
use SDPHP\PHPMicrork\Loop\GameLoop;
14-
use SDPHP\PHPMicrork\State\GameStateInterface;
14+
use SDPHP\PHPMicrork\State\StateInterface;
1515
use Symfony\Component\Config\Loader\DelegatingLoader;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Input\InputArgument;
@@ -42,7 +42,7 @@ class GameCommand extends Command
4242
*/
4343
private $gameLogic;
4444

45-
public function __construct(DelegatingLoader $delegatingLoader, GameStateInterface $gameState, GameLogicInterface $gameLogic, $name = null)
45+
public function __construct(DelegatingLoader $delegatingLoader, StateInterface $gameState, GameLogicInterface $gameLogic, $name = null)
4646
{
4747
parent::__construct($name);
4848
$this->delegatingLoader = $delegatingLoader;
@@ -53,7 +53,7 @@ public function __construct(DelegatingLoader $delegatingLoader, GameStateInterfa
5353
protected function configure()
5454
{
5555
$this
56-
->setName('micrork:run')
56+
->setName('run')
5757
->setDescription('Main command to start a new PHPOrk game.')
5858
->addArgument(
5959
'name',
@@ -85,16 +85,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
8585
$gameIO = new GameCLIIO($questionHelper, $input, $output);
8686
$gameLoop = new GameLoop($gameIO);
8787
$this->gameState->getPlayer()->setName($name);
88-
$next = true;
8988

90-
while ($next !== false) {
91-
$this->gameState->setLevel( $this->currentLevel['level']);
89+
while (!$this->gameState->isStateOver()) {
90+
$this->gameState->setProperty('level', $this->currentLevel['level']);
9291
$gameLoop->start($this->gameState, $this->gameLogic);
93-
94-
if ($this->gameState->isGameOver()) {
95-
$next = false;
96-
} elseif ($this->gameState->isLevelOver()) {
97-
$next = $this->gameState->getNextLevel();
92+
$next = $this->gameState->getProperty('next_level', false);
93+
if ($next) {
9894
$this->loadLevel($next);
9995
}
10096
}

src/Logic/BasicGameLogic.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
use SDPHP\PHPMicrork\IO\GameIOInterface;
1111
use SDPHP\PHPMicrork\Loop\FightLoop;
12-
use SDPHP\PHPMicrork\State\GameStateInterface;
12+
use SDPHP\PHPMicrork\Player\BasicNPC;
13+
use SDPHP\PHPMicrork\State\StateInterface;
1314

1415
/**
1516
* BasicGameLogic - Description.
@@ -18,12 +19,14 @@
1819
*/
1920
class BasicGameLogic implements GameLogicInterface
2021
{
21-
public function switchState(GameStateInterface $gameState, GameIOInterface $gameIO)
22+
public function switchState(StateInterface $gameState, GameIOInterface $gameIO)
2223
{
23-
$room = $gameState->getRoom();
24+
$location = $gameState->getProperty('location');
25+
$locationProperty = sprintf('level[room][%s]', $location);
26+
$room = $gameState->getProperty($locationProperty);
2427
$directions = $room['directions'];
25-
$gameIO->printPlace($room);
2628

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

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

4346
case 'south':
4447
if (isset($directions[$command]) && $directions[$command] !== '-') {
45-
$gameState->setPosition($directions[$command]);
48+
$gameState->setProperty('location', $directions[$command]);
4649
} else {
4750
$gameIO->printError("You cannot go south!");
4851
}
4952
break;
5053

5154
case 'west':
5255
if (isset($directions[$command]) && $directions[$command] !=='-') {
53-
$gameState->setPosition($directions[$command]);
56+
$gameState->setProperty('location', $directions[$command]);
5457
} else {
5558
$gameIO->printError("You cannot go west!");
5659
}
5760
break;
5861

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

7174
case 'fight':
7275
if ($argument) {
73-
$gameState->loadNPC($argument);
76+
$gameState->setNpc(new BasicNPC($argument));
7477
$fightLoop = new FightLoop($gameIO);
7578
$fightLoop->start($gameState, new FightLogic());
7679

@@ -92,7 +95,7 @@ public function switchState(GameStateInterface $gameState, GameIOInterface $game
9295
if ($argument) {
9396
$gameIO->printComment(sprintf('Drinking %s, glup...', $argument));
9497
if ($argument === 'water') {
95-
$gameIO->printComment('Sissy!');
98+
$gameIO->printComment('You hear a drunken warrion in the distance yell: "Sissy!"');
9699
}
97100
} else {
98101
$gameIO->printError('You need to choose what you are Drinking');

src/Logic/FightLogic.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*/
88

99
namespace SDPHP\PHPMicrork\Logic;
10-
use SDPHP\PHPMicrork\State\GameStateInterface;
10+
11+
use SDPHP\PHPMicrork\State\StateInterface;
1112
use SDPHP\PHPMicrork\IO\GameIOInterface;
1213

1314

@@ -19,10 +20,11 @@
1920
class FightLogic implements GameLogicInterface
2021
{
2122

22-
public function switchState(GameStateInterface $state, GameIOInterface $gameIO)
23+
public function switchState(StateInterface $state, GameIOInterface $gameIO)
2324
{
2425
$player = $state->getPlayer();
25-
$npc = $state->getNPC();
26+
$npc = $state->getNPCs();
27+
2628
// TODO: Implement switchState() method.
2729
}
2830
}

src/Logic/GameLogicInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
* please view the LICENSE file that was distributed
66
* with this source code.
77
*/
8+
89
namespace SDPHP\PHPMicrork\Logic;
910

1011
use SDPHP\PHPMicrork\IO\GameIOInterface;
11-
use SDPHP\PHPMicrork\State\GameStateInterface;
12+
use SDPHP\PHPMicrork\State\StateInterface;
1213

1314
/**
1415
* LogicInterface - Description.
@@ -17,5 +18,5 @@
1718
*/
1819
interface GameLogicInterface
1920
{
20-
public function switchState(GameStateInterface $state, GameIOInterface $gameIO);
21+
public function switchState(StateInterface $state, GameIOInterface $gameIO);
2122
}

src/Loop/AbstractGameLoop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use SDPHP\PHPMicrork\IO\GameIOInterface;
1111
use SDPHP\PHPMicrork\Logic\GameLogicInterface;
12-
use SDPHP\PHPMicrork\State\GameStateInterface;
12+
use SDPHP\PHPMicrork\State\StateInterface;
1313

1414
/**
1515
* AbstractGameLoopo - Description.
@@ -28,5 +28,5 @@ public function __construct(GameIOInterface $gameIO)
2828
$this->gameIO = $gameIO;
2929
}
3030

31-
abstract public function start(GameStateInterface $gameState, GameLogicInterface $gameLogic);
31+
abstract public function start(StateInterface $gameState, GameLogicInterface $gameLogic);
3232
}

0 commit comments

Comments
 (0)