View Source Hangman.Engine (Hangman Engine v0.1.62)

Models the Hangman Game. Times out after 30 minutes of inactivity.

Based on the course Elixir for Programmers by Dave Thomas.

Summary

Functions

Stops a game server process normally. It won't be restarted.

Makes a move by guessing a letter.

Starts a new game server process and supervises it.

Returns the tally of a game.

Functions

@spec end_game(Hangman.Game.name()) :: :ok

Stops a game server process normally. It won't be restarted.

Examples

iex> alias Hangman.Engine
iex> Engine.new_game("Ben")
iex> Engine.end_game("Ben")
:ok
Link to this function

make_move(game_name, guess)

View Source

Makes a move by guessing a letter.

Examples

iex> alias Hangman.Engine
iex> Engine.new_game("Ed")
iex> Engine.make_move("Ed", "a").game_state in [:good_guess, :bad_guess]
true

Starts a new game server process and supervises it.

Examples

iex> alias Hangman.Engine
iex> {:ok, game_id} = Engine.new_game("Meg")
iex> {:error, {:already_started, ^game_id}} = Engine.new_game("Meg")
iex> is_pid(game_id)
true

Returns the tally of a game.

Examples

iex> alias Hangman.Engine
iex> Engine.new_game("Jim")
iex> tally = Engine.tally("Jim")
iex> %{
...>   game_state: :initializing,
...>   turns_left: 7,
...>   letters: letters,
...>   guesses: []
...> } = tally
iex> all_underscores? = Enum.all?(letters, & &1 == "_")
iex> is_list(letters) and length(letters) > 0 and all_underscores?
true