/** * create land move for user * * @param int $start (id_zarea) * @param int $destination (id_zarea) * @param array $units (int $id_unit -> $int count) * @throws NullPointerException * @throws ControllerException * @return ModelTroopsMove */ public function createMove($start, $destination, array $units) { $start = intval($start); $destination = intval($destination); // check if already fixated if ($this->checkIfDone()) { throw new ControllerException('LandMove already finished.'); } // check if processing $game = ModelGame::getGame($this->id_game); if ($game->checkProcessing()) { throw new ControllerException('Unable to create moves at this moment as the game-logic is currently processing.'); } // check if countries picked if ($start === 0 || $destination === 0) { throw new ControllerException('Choose a start and destination country.'); } // check for units $unit_count = 0; foreach ($units as $count) { if ($count < 0) { throw new ControllerException('No negative unit numbers allowed.'); } $unit_count += $count; } if ($unit_count === 0) { throw new ControllerException('Choose at least one unit.'); } // check if start and destination is the same if ($start === $destination) { throw new ControllerException('Units have to move at least 1 country.'); } $steps = array(); $steps[1] = $start; $steps[2] = $destination; $round = (int) $game->getRound(); $phase = (int) $game->getIdPhase(); if ($phase > PHASE_TROOPSMOVE) { ++$round; } $this->validateMove(0, $round, $steps, $units); return ModelTroopsMove::createMove($this->id_user, $this->id_game, $round, $steps, $units); }