99
1010use SDPHP \PHPMicrork \IO \GameIOInterface ;
1111use 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.
1819 */
1920class 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 ' );
0 commit comments