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

Commit 0e40b18

Browse files
committed
Update to game command to use new game state.
1 parent e41efd8 commit 0e40b18

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

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
}

0 commit comments

Comments
 (0)