Islands Engine v0.2.0 Islands.Engine.Game View Source

Link to this section Summary

Link to this section Types

Link to this type

player_id() View Source
player_id() :: :player1 | :player2

Link to this section Functions

Invoked in order to access the value stored under key in the given term term.

This function should return {:ok, value} where value is the value under key if the key exists in the term, or :error if the key does not exist in the term.

Many of the functions defined in the Access module internally call this function. This function is also used when the square-brackets access syntax (structure[key]) is used: the fetch/2 callback implemented by the module that defines the structure struct is invoked and if it returns {:ok, value} then value is returned, or if it returns :error then nil is returned.

See the Map.fetch/2 and Keyword.fetch/2 implementations for examples of how to implement this callback.

Callback implementation for Access.fetch/2.

Link to this function

get_and_update(game, key, fun) View Source

Invoked in order to access the value under key and update it at the same time.

The implementation of this callback should invoke fun with the value under key in the passed structure data, or with nil if key is not present in it. This function must return either {get_value, update_value} or :pop.

If the passed function returns {get_value, update_value}, the return value of this callback should be {get_value, new_data}, where:

  • get_value is the retrieved value (which can be operated on before being returned)

  • update_value is the new value to be stored under key

  • new_data is data after updating the value of key with update_value.

If the passed function returns :pop, the return value of this callback must be {value, new_data} where value is the value under key (or nil if not present) and new_data is data without key.

See the implementations of Map.get_and_update/3 or Keyword.get_and_update/3 for more examples.

Callback implementation for Access.get_and_update/3.

Link to this function

new(name, player1_name, pid) View Source
new(String.t(), String.t(), pid()) :: t() | {:error, atom()}

Link to this function

notify_player(game, player_id) View Source
notify_player(t(), player_id()) :: t()

Link to this function

player_board(game, player_id) View Source
player_board(t(), player_id()) :: Islands.Engine.Board.t()

Invoked to "pop" the value under key out of the given data structure.

When key exists in the given structure data, the implementation should return a {value, new_data} tuple where value is the value that was under key and new_data is term without key.

When key is not present in the given structure, a tuple {value, data} should be returned, where value is implementation-defined.

See the implementations for Map.pop/3 or Keyword.pop/3 for more examples.

Callback implementation for Access.pop/2.

Link to this function

update_board(game, player_id, board) View Source
update_board(t(), player_id(), Islands.Engine.Board.t()) :: t()

Link to this function

update_guesses(game, player_id, hit_or_miss, guess) View Source
update_guesses(
  t(),
  player_id(),
  Islands.Engine.Guesses.type(),
  Islands.Engine.Coord.t()
) :: t()

Link to this function

update_player_name(game, player_id, name) View Source
update_player_name(t(), player_id(), String.t()) :: t()

Link to this function

update_player_pid(game, player_id, pid) View Source
update_player_pid(t(), player_id(), pid()) :: t()

Link to this function

update_request(game, request) View Source
update_request(t(), Islands.Engine.Game.Server.request()) :: t()

Link to this function

update_response(game, response) View Source
update_response(t(), Islands.Engine.Game.Server.response()) :: t()

Link to this function

update_state(game, state) View Source
update_state(t(), Islands.Engine.Game.State.t()) :: t()