/** * @param $playerOne * @param $playerTwo * @return array */ public function run(Combatant $playerOne, Combatant $playerTwo) { $output = []; $playerOneHealth = $playerOne->getHealth(); if ($playerOne->isStunned()) { $output[] = $playerOne->getName() . " is stunned and misses attack turn"; return $output; } $output[] = $playerOne->getName() . " attacks"; $hit = $playerOne->attack($playerTwo); if ($hit) { $output[] = $playerOne->getName() . " does " . $hit . " damage"; if ($playerTwo->isStunned()) { $output[] = $playerTwo->getName() . " is stunned"; } } else { $output[] = $playerTwo->getName() . " dodged the attack"; if ($playerOne->getHealth() !== $playerOneHealth) { $lostHealth = $playerOneHealth - $playerOne->getHealth(); $output[] = $playerOne->getName() . " lost " . $lostHealth . " health during the attack"; } } return $output; }
/** * @param $playerOne * @param $playerTwo * @param $turn */ protected function outputEndGameInformation(Combatant $playerOne, Combatant $playerTwo, $turn) { if ($turn >= 30) { $this->info("The battle was a draw"); } else { $winner = $playerOne->isAlive() ? $playerOne : $playerTwo; $loser = !$playerOne->isAlive() ? $playerOne : $playerTwo; $this->info($loser->getName() . " has died in battle."); $this->info("The winner is " . $winner->getName()); } }