/** * @param Cell[] $cells * @param Game $game */ public function __construct(Game $game, array $cells) { if (null !== $game->getResult()) { $this->setResult($game->getResult()); } $this->setCells($cells); }
public static function getGameMock(int $players = 2, int $size = 7) : Game { $game = new Game(); for ($i = 0; $i < $players; $i++) { $game->addBattlefield(static::getBattlefieldMock($size)); } return $game; }
protected function attachAIBattlefields(Game $game, int $amount, int $size) { for ($i = 0; $i < $amount; $i++) { $player = $this->playerModel->createOnRequestAIControlled("CPU {$i}"); /** hard-code ship into B2 for testing purposes */ $battlefield = BattlefieldModel::generate($size, ['B2'])->setPlayer($player); $game->addBattlefield($battlefield); } }
/** * @since 21.1 * * @param Game $game * @param Player $attacker * @param Cell $cell * * @return bool - true if game been won, otherwise false */ protected function processPlayerTurnOnBattlefields(Game $game, Player $attacker, Cell $cell) : bool { foreach ($game->getBattlefields() as $battlefield) { try { if ($this->processPlayerTurnOnBattlefield($battlefield, $attacker, $cell)) { return true; } } catch (GameProcessorException $e) { continue; } } return false; }