Пример #1
0
 /**
  * Returns an action alias map from the generic commands, plus the commands from the current scene
  *
  * @return array
  */
 protected function getActionAliasMap()
 {
     // Generic aliases
     $aliases = $this->adventure->getActionAliasMap();
     // Merge with current scene aliases
     $aliases = array_merge($aliases, $this->adventure->getState()->getScene()->getActionAliasMap());
     return $aliases;
 }
Пример #2
0
 function execute(Adventure $adventure, Scene $scene, array $args)
 {
     $inv = $adventure->getState()->getInventory();
     if (count($inv) == 0) {
         $adventure->output("You don't carry anything with you.");
         return;
     }
     $adventure->output(sprintf("You carry %d item(s) in your inventory:\n", count($inv)));
     foreach ($inv as $object) {
         $adventure->output(sprintf(" *  <info>%s</info> : %s\n", $object->getName(), $object->getSummary()));
     }
 }
Пример #3
0
    function execute(Adventure $adventure, Scene $scene, array $args)
    {
        $help = <<<EOT
Generic actions:
  <info>help</info>                   <comment>Give help info</comment>
  <info>inventory</info>              <comment>Display all items in your inventory</comment>
  <info>look [around]</info>          <comment>Get detailed information about your surroundings</comment>
  <info>look [at [object]]</info>     <comment>View object details</comment>
  <info>pick up [object]</info>       <comment>Pick up object into inventory</comment>
  <info>drop [object]</info>          <comment>Drop object from inventory</comment>
  <info>go north | north | n</info>   <comment>Go north (or south, west, east)</comment>

Other actions are available too, just use your imagination to '<info>use key on chest</info>' or '<info>talk to stranger</info>'.

EOT;
        $adventure->output($help);
    }
Пример #4
0
 /**
  * Turn a lamp on and off
  *
  * @otas\command('turn_lamp_on');
  * @otas\command('turn_lamp_off');
  */
 function turn_lamp_on(Adventure $adventure, Scene $scene, array $command)
 {
     if ($command[2] == 'on') {
         if ($scene->objects['lamp']->vars['lit']) {
             $adventure->output('The lamp is already on');
         } else {
             $scene->objects['lamp']->vars['lit'] = true;
             $scene->lit = true;
             $adventure->output('You turn on the light. The room seems a lot less darker now. You notice a small piece of paper lying on the floor.');
         }
     }
     if ($command[2] == 'off') {
         if (!$scene->objects['lamp']->vars['lit']) {
             $adventure->output('The lamp is already off');
         } else {
             $scene->objects['lamp']->vars['lit'] = false;
             $scene->lit = false;
             $adventure->output('You turn off the light. Strangely enough, you can see less.');
         }
     }
 }
Пример #5
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);
     }
 }
Пример #6
0
 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);
 }
Пример #7
0
 function execute(Adventure $adventure, Scene $scene, array $args)
 {
     if (count($args) <= 1) {
         $adventure->output("Look at what?");
         return;
     }
     if ($args[1] == 'around') {
         // Look around
         $adventure->output("<question>" . $adventure->getState()->getScene()->getTitle() . "</question>\n");
         $adventure->output("\n");
         $adventure->output($adventure->getState()->getScene()->getDescription() . "\n");
         $adventure->output("\n");
         $exits = $adventure->getState()->getScene()->getExits();
         $str = join(", ", $adventure->getState()->getScene()->getExits()->getKeys());
         if (count($exits) == 1) {
             $adventure->output("There is " . count($exits) . " exit to the " . $str . ".\n");
         } else {
             $adventure->output("There are " . count($exits) . " exits: " . $str . "\n");
         }
         $adventure->output("\n");
     } else {
         //Look at object
         $object = $scene->getObject($args[1]);
         if (!$object) {
             $adventure->output("There is no " . $args[1] . " to look at.");
         }
         $adventure->output("You look at " . $object->getName());
         $adventure->output($object->getDescription());
     }
 }