Exemplo n.º 1
0
 public function findBestSpellToCast(Boss $boss, EffectTracker $effectTracker)
 {
     if ($this->recharge > 0 && $effectTracker->has(Spells\RechargeSpell::class) === false && $this->mana >= 229 && $this->mana < 402) {
         $this->recharge--;
         return new Spells\RechargeSpell();
     }
     if ($this->shield > 0 && $effectTracker->has(Spells\ShieldSpell::class) === false && $this->health <= $boss->getDamage() * 3 && $this->mana >= 113) {
         $this->shield--;
         return new Spells\ShieldSpell();
     }
     if ($this->drain > 0 && $effectTracker->has(Spells\DrainSpell::class) === false && $this->mana >= 73) {
         $this->drain--;
         return new Spells\DrainSpell();
     }
     if ($boss->getHealth() <= 8 && $this->mana >= 53) {
         return new Spells\MagicMissileSpell();
     }
     if ($effectTracker->has(Spells\PoisonSpell::class) === false && $this->mana >= 173) {
         return new Spells\PoisonSpell();
     }
     if ($this->mana >= 53) {
         return new Spells\MagicMissileSpell();
     }
     throw new OutOfManaException();
 }
Exemplo n.º 2
0
 public function apply(Player $player, Boss $boss, $turns)
 {
     $boss->inflictDamage(3);
     if ($boss->isDead()) {
         return;
     }
 }
Exemplo n.º 3
0
 protected function simulateHarderBattle($health, $mana, $bossStats)
 {
     $numberOfRecharge = 0;
     $numberOfShield = 0;
     $numberOfDrain = 0;
     $iterations = 0;
     $shieldFailed = true;
     while (true) {
         $iterations++;
         $player = new PlayerTwo($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) {
                 $player->reduceHealth(1);
                 if ($player->isDead()) {
                     break;
                 }
                 $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 ($shieldFailed === false) {
             $numberOfDrain++;
             $shieldFailed = true;
         } else {
             $numberOfShield++;
             $shieldFailed = false;
         }
         $numberOfRecharge = 0;
     }
     return $player->getManaSpent();
 }
Exemplo n.º 4
0
 public function cast(Player $player, Boss $boss, EffectTracker $effects)
 {
     $player->reduceMana($this->getCost());
     $player->giveHealth(2);
     $boss->inflictDamage(2);
 }