protected function simulateBattle($health, $mana, $bossStats)
 {
     $numberOfRecharge = 0;
     $numberOfShield = 0;
     $numberOfDrain = 0;
     $iterations = 0;
     while (true) {
         $iterations++;
         $player = new Player($health, $mana, $numberOfRecharge, $numberOfShield, $numberOfDrain, $this->output);
         $boss = new Boss($bossStats['Hit Points'], $bossStats['Damage'], $this->output);
         $effects = new EffectTracker($player, $boss);
         $spells = [];
         try {
             while (true) {
                 $effects->apply();
                 if ($boss->isDead()) {
                     break;
                 }
                 $spell = $player->findBestSpellToCast($boss, $effects);
                 $spells[] = get_class($spell);
                 $spell->cast($player, $boss, $effects);
                 $effects->apply();
                 if ($boss->isDead()) {
                     break;
                 }
                 $boss->attack($player);
                 if ($player->isDead()) {
                     break;
                 }
             }
         } catch (OutOfManaException $e) {
             $numberOfRecharge++;
             continue;
         }
         if ($boss->isDead()) {
             break;
         }
         if ($effects->has(Spells\ShieldSpell::class)) {
             $numberOfDrain++;
         } else {
             $numberOfShield++;
         }
     }
     return $player->getManaSpent();
 }
Example #2
0
 public function cast(Player $player, Boss $boss, EffectTracker $effects)
 {
     $player->reduceMana($this->getCost());
     $effects->add($this);
 }
Example #3
0
 public function cast(Player $player, Boss $boss, EffectTracker $effects)
 {
     $player->reduceMana($this->getCost());
     $player->giveHealth(2);
     $boss->inflictDamage(2);
 }