v0.1.0 GameApp.Game
GameApp.Game
defines a struct that encapsulates game state as well as many
functions that advance the game state based on actions that players can take.
Link to this section Summary
Functions
Creates a game.
Adds a player to a game.
Removes a player from a game. Removing a player doesn't remove their score which allows for a player to possibly leave and rejoin a game in progress without losing their prior points.
Assigns a prompt to the current round.
Adds a reaction in the current round for the given player.
Starts prompt selection for the current round.
Starts a game. Requires at least 3 players including the creator.
Starts prompt selection for the current round.
Starts a round.
Returns a summary of the game state.
Link to this section Types
game_state()
game_state() :: :lobby | :game_start | :round_start | :prompt_selection | :reaction_selection | :winner_selection | :round_end | :game_end
t()
t() :: %GameApp.Game{ config: GameApp.Config.t(), creator: GameApp.Player.t(), funmaster: GameApp.Player.t() | nil, funmaster_order: [String.t()], phase: game_state(), players: %{optional(String.t()) => GameApp.Player.t()}, round_number: integer() | nil, rounds: [GameApp.Round.t()], scores: %{optional(String.t()) => integer()}, shortcode: String.t(), winners: [GameApp.Player.t()] }
Link to this section Functions
all_players_reacted?(game)
Creates a game.
Examples
iex> Game.create(shortcode: "ABCD", creator: Player.create(id: "1", name: "Gamer"))
%Game{
shortcode: "ABCD",
creator: %Player{id: "1", name: "Gamer"},
players: %{"1" => %Player{id: "1", name: "Gamer"}},
scores: %{"1" => 0},
funmaster: %Player{id: "1", name: "Gamer"},
funmaster_order: ["1"]
}
final_round?(arg1)
finalize(game)
is_empty?(arg1)
player_join(game, player)
player_join(GameApp.Game.t(), GameApp.Player.t()) :: GameApp.Game.t()
Adds a player to a game.
Examples
iex> :rand.seed(:exsplus, {1, 2, 3})
iex> g = Game.create(shortcode: "ABCD", creator: Player.create(id: "1", name: "Gamer"))
iex> Game.player_join(g, Player.create(id: "2", name: "Gamer2"))
%Game{
shortcode: "ABCD",
creator: %Player{id: "1", name: "Gamer"},
players: %{
"1" => %Player{id: "1", name: "Gamer"},
"2" => %Player{id: "2", name: "Gamer2"}
},
scores: %{"1" => 0, "2" => 0},
funmaster: %Player{id: "1", name: "Gamer"},
funmaster_order: ["1", "2"]
}
player_leave(game, player)
player_leave(GameApp.Game.t(), GameApp.Player.t()) :: GameApp.Game.t()
Removes a player from a game. Removing a player doesn't remove their score which allows for a player to possibly leave and rejoin a game in progress without losing their prior points.
Examples
iex> :rand.seed(:exsplus, {1, 2, 3})
iex> p1 = Player.create(id: "1", name: "Gamer")
iex> p2 = Player.create(id: "2", name: "Gamer2")
iex> g = Game.create(shortcode: "ABCD", creator: p1)
iex> g = Game.player_join(g, p2)
iex> Game.player_leave(g, p2)
%Game{
shortcode: "ABCD",
creator: %Player{id: "1", name: "Gamer"},
players: %{"1" => %Player{id: "1", name: "Gamer"}},
scores: %{"1" => 0, "2" => 0},
funmaster: %Player{id: "1", name: "Gamer"},
funmaster_order: ["1", "2"]
}
select_prompt(game, prompt)
select_prompt(GameApp.Game.t(), String.t()) :: GameApp.Game.t()
Assigns a prompt to the current round.
select_reaction(game, player, reaction)
select_reaction(GameApp.Game.t(), GameApp.Player.t(), String.t()) :: GameApp.Game.t()
Adds a reaction in the current round for the given player.
select_winner(game, player)
select_winner(GameApp.Game.t(), GameApp.Player.t() | nil) :: GameApp.Game.t()
Starts prompt selection for the current round.
Starts a game. Requires at least 3 players including the creator.
Examples
iex> :rand.seed(:exsplus, {1, 2, 3})
iex> p1 = Player.create(id: "1", name: "Gamer1")
iex> p2 = Player.create(id: "2", name: "Gamer2")
iex> p3 = Player.create(id: "3", name: "Gamer3")
iex> g = Game.create(shortcode: "ABCD", creator: p1)
...> |> Game.player_join(p2)
...> |> Game.player_join(p3)
iex> Game.start_game(g)
%Game{
shortcode: "ABCD",
phase: :game_start,
creator: %Player{id: "1", name: "Gamer1"},
players: %{
"1" => %Player{id: "1", name: "Gamer1"},
"2" => %Player{id: "2", name: "Gamer2"},
"3" => %Player{id: "3", name: "Gamer3"}
},
scores: %{
"1" => 0,
"2" => 0,
"3" => 0
},
funmaster: %Player{id: "2", name: "Gamer2"},
funmaster_order: ["2", "3", "1"]
}
start_prompt_selection(game)
start_prompt_selection(GameApp.Game.t()) :: GameApp.Game.t()
Starts prompt selection for the current round.
Starts a round.
Examples
iex> :rand.seed(:exsplus, {1, 2, 3})
iex> p1 = Player.create(id: "1", name: "Gamer1")
iex> p2 = Player.create(id: "2", name: "Gamer2")
iex> p3 = Player.create(id: "3", name: "Gamer3")
iex> g = Game.create(shortcode: "ABCD", creator: p1)
...> |> Game.player_join(p2)
...> |> Game.player_join(p3)
iex> g = Game.start_game(g)
iex> Game.start_round(g)
%Game{
shortcode: "ABCD",
phase: :round_start,
round_number: 1,
creator: %Player{id: "1", name: "Gamer1"},
players: %{
"1" => %Player{id: "1", name: "Gamer1"},
"2" => %Player{id: "2", name: "Gamer2"},
"3" => %Player{id: "3", name: "Gamer3"}
},
scores: %{
"1" => 0,
"2" => 0,
"3" => 0
},
funmaster: %Player{id: "3", name: "Gamer3"},
funmaster_order: ["3", "1", "2"],
rounds: [
%Round{number: 1, prompt: nil, reactions: %{}, winner: nil}
]
}
start_winner_selection(game)
Returns a summary of the game state.
Examples
iex> g = Game.create(shortcode: "ABCD", creator: Player.create(id: "1", name: "Gamer"))
iex> Game.summary(g)
%{
creator: %Player{id: "1", name: "Gamer"},
funmaster: %Player{id: "1", name: "Gamer"},
phase: :lobby,
players: %{"1" => %Player{id: "1", name: "Gamer"}},
player_count: 1,
prompt: nil,
reactions: %{},
reaction_count: 0,
ready_to_start: false,
round_winner: nil,
round_number: 1,
scores: %{"1" => 0},
shortcode: "ABCD",
winners: [],
final_round: true,
config: %GameConfig{}
}