Skip to content

Commit

Permalink
Sets islands
Browse files Browse the repository at this point in the history
  • Loading branch information
jrowah committed Dec 30, 2023
1 parent 8dd0aef commit a0e0d8d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/islands_engine/game.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0e0d8d

Please sign in to comment.