Ejemplo n.º 1
0
Archivo: Go.php Proyecto: jaytaph/otas
 function execute(Adventure $adventure, Scene $scene, array $args)
 {
     if (count($args) <= 1) {
         $adventure->output("Where to?");
         return;
     }
     $direction = $args[1];
     if (!$scene->getExits()->containsKey($direction)) {
         $adventure->output('Cannot go ' . $direction);
         return;
     }
     $key = $scene->getExits()->get($direction);
     $newScene = $adventure->getScene($key);
     $adventure->getState()->setScene($newScene);
     list($action, $args) = $adventure->parse("look around");
     $action->execute($adventure, $adventure->getState()->getScene(), $args);
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // @TODO: Make sure we validate our configuration
     $io = new Cli($input, $output);
     $config = Config::load($input->getArgument('dir'));
     $scenes = SceneLoader::load($config);
     $adventure = new Adventure($io, $config, $scenes);
     // Display the start of the adventure
     $output->writeln($adventure->getConfig()['start']);
     list($action, $args) = $adventure->parse("help");
     $action->execute($adventure, $adventure->getState()->getScene(), $args);
     // Initialize vars
     $wrongParsedOrders = 0;
     // And go!
     while (true) {
         $output->writeln("");
         // Ask a question
         $question = new Question("<comment>[scene: <info>" . $adventure->getState()->getScene()->getTitle() . "</info>] [inv: <info>" . count($adventure->getState()->getInventory()) . "</info>]</comment> > ");
         $qh = new QuestionHelper();
         $action = $qh->ask($input, $output, $question);
         if (trim($action) == "") {
             continue;
         }
         try {
             list($action, $args) = $adventure->parse($action);
             $wrongParsedOrders = 0;
         } catch (ParseException $e) {
             $output->writeln($e->getMessage());
             $wrongParsedOrders++;
             // If we have three unprocessed actions, it's time to hint the user for help
             if ($wrongParsedOrders > 3) {
                 // Maybe the user is stuck?
                 $output->writeln("Do you need some <info>help</info>?");
             }
             continue;
         }
         $action->execute($adventure, $adventure->getState()->getScene(), $args);
     }
 }