/** * Battle::startBattle() * * @return null */ public function startBattle($debug = false) { if (!$debug) { ob_start(); } $this->battleStarted = true; //only for initial fleets presentation log_var('attackers', $this->attackers); log_var('defenders', $this->defenders); $round = new Round($this->attackers, $this->defenders, 0); $this->report->addRound($round); for ($i = 1; $i <= ROUNDS; $i++) { $att_lose = $this->attackers->isEmpty(); $deff_lose = $this->defenders->isEmpty(); //if one of they are empty then battle is ended, so update the status if ($att_lose || $deff_lose) { $this->checkWhoWon($att_lose, $deff_lose); $this->report->setBattleResult($this->attackers->battleResult, $this->defenders->battleResult); if (!$debug) { ob_get_clean(); } return; } //initialize the round $round = new Round($this->attackers, $this->defenders, $i); $round->startRound(); //add the round to the combatReport $this->report->addRound($round); //if($i==2) die('Round: '.$this->report->getRound(0)->getNumber()); // ERRORE //update the attackers and defenders after round $this->attackers = $round->getAfterBattleAttackers(); $this->defenders = $round->getAfterBattleDefenders(); } //check status after all rounds $this->checkWhoWon($this->attackers->isEmpty(), $this->defenders->isEmpty()); if (!$debug) { ob_get_clean(); } return true; }