コード例 #1
0
ファイル: Game.php プロジェクト: Ranmus/CDV-Combat
 /**
  * Wypij eliksir
  * @param \Game\Person $person
  * @return bool efekt
  */
 private function drinkPotion(Person $person)
 {
     $inventory = $person->getInventory();
     if ($inventory->getItemsCount() == 0) {
         CLI::write("{$person} aktualnie nie ma nic w plecaku!");
         return false;
     }
     CLI::write("", true);
     CLI::write("Wybierz jeden z eliksirow:");
     $i = 0;
     foreach ($inventory->getItems() as $item) {
         if (!in_array('Game\\Inventory\\Drinkable', class_implements($item))) {
             continue;
         }
         $i++;
         CLI::write("[{$i}] {$item}");
     }
     $i++;
     CLI::write("[{$i}] Anuluj");
     $index = CLI::readDefinedValues(range(1, $i), $i);
     if ($index == $i) {
         return;
     }
     // Pobierz i wypij eliksir
     $potion = $inventory->removeItem($index - 1);
     $person->drink($potion);
     CLI::write("", true);
     CLI::write("{$person} wypija {$potion}");
     if ($person->getVitality() <= 0) {
         CLI::write("Ojojojoj, {$person} otrul sie eliksirem na smierc!");
         $person->setVitality(0);
     } else {
         CLI::write("Statystyki {$person} po wypiciu: " . $person->getStats());
     }
     return true;
 }