1111use SDPHP \PHPMicrork \IO \GameCLIIO ;
1212use SDPHP \PHPMicrork \Logic \GameLogicInterface ;
1313use SDPHP \PHPMicrork \Loop \GameLoop ;
14- use SDPHP \PHPMicrork \State \GameStateInterface ;
14+ use SDPHP \PHPMicrork \State \StateInterface ;
1515use Symfony \Component \Config \Loader \DelegatingLoader ;
1616use Symfony \Component \Console \Command \Command ;
1717use 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