diff --git a/lib/islands_engine/game.ex b/lib/islands_engine/game.ex index b0209e8..2b7dfda 100644 --- a/lib/islands_engine/game.ex +++ b/lib/islands_engine/game.ex @@ -19,6 +19,23 @@ defmodule IslandEngine.Game do def position_island(game, player, key, row, col) when player in @players, do: GenServer.call(game, {:position_island, player, key, row, col}) + def set_islands(game, player) when player in @players, + do: GenServer.call(game, {:set_islands, player}) + + def handle_call({:set_islands, player}, _from, state_data) do + board = player_board(state_data, player) + + with {:ok, rules} <- Rules.check(state_data.rules, {:set_islands, player}), + true <- Board.all_islands_positioned?(board) do + state_data + |> update_rules(rules) + |> reply_success({:ok, board}) + else + :error -> {:reply, :error, state_data} + false -> {:reply, {:error, :not_all_islands_positioned}, state_data} + end + end + def handle_call({:add_player, name}, _from, state_data) do with {:ok, rules} <- Rules.check(state_data.rules, :add_player) do state_data