Hangman.Game (Hangman Game v0.1.5) View Source
A game struct and functions for the Hangman Game.
The game struct contains the fields game_name
, turns_left
, game_state
,
letters
and used
representing the characteristics of a game in the
Hangman Game.
Based on the course Elixir for Programmers by Dave Thomas.
Link to this section Summary
Types
Letter from a
to z
or _
(underscore)
Game name
Game state
A game struct for the Hangman Game
A tally struct for the Hangman Game
Functions
Makes a move by guessing a letter.
Returns a game struct given a game_name
and a word
to be guessed.
Returns a random name of 4 to 10 characters.
Returns a tally struct externalizing game
.
Link to this section Types
Specs
letter() :: String.codepoint()
Letter from a
to z
or _
(underscore)
Specs
name() :: String.t()
Game name
Specs
state() :: :initializing | :good_guess | :bad_guess | :already_used | :lost | :won
Game state
Specs
t() :: %Hangman.Game{ game_name: name(), game_state: state(), letters: [letter()], turns_left: turns_left(), used: used() }
A game struct for the Hangman Game
Specs
tally() :: %{ game_state: state(), turns_left: turns_left(), letters: [letter() | charlist()], guesses: [letter()] }
A tally struct for the Hangman Game
Specs
turns_left() :: 0..7
Specs
Link to this section Functions
Specs
Makes a move by guessing a letter.
Examples
iex> alias Hangman.Game
iex> game = Game.random_name() |> Game.new()
iex> Game.make_move(game, "a").game_state in [:good_guess, :bad_guess]
true
Specs
Returns a game struct given a game_name
and a word
to be guessed.
Examples
iex> alias Hangman.Game
iex> Game.new("Mr Smith").game_state
:initializing
Specs
random_name() :: name()
Returns a random name of 4 to 10 characters.
Examples
iex> alias Hangman.Game
iex> for _ <- 0..99, uniq: true do
iex> length = Game.random_name() |> String.length()
iex> length in 4..10
iex> end
[true]
Specs
Returns a tally struct externalizing game
.
Examples
iex> alias Hangman.Game
iex> game = Game.random_name() |> Game.new()
iex> game = Game.make_move(game, "a")
iex> Game.tally(game).turns_left in 6..7
true