diff --git a/lib/viral_spiral/game.ex b/lib/viral_spiral/game.ex index adba49e..2b3e860 100644 --- a/lib/viral_spiral/game.ex +++ b/lib/viral_spiral/game.ex @@ -1,16 +1,30 @@ defmodule ViralSpiral.Game do - defstruct room: nil, - player_list: nil, - player_map: nil, - scores: nil - - @moduledoc """ - Context for the game. - - Rounds and Turns - round = Round.new(players) - round_order = Round.order(round) - During a Round every player gets to draw a card and then take some actions. - When a round begins, we also start a Turn. Within each Round there's a turn that includes everyone except the person who started the turn. - """ + alias ViralSpiral.Game.Room + alias ViralSpiral.Game.State + + @spec create_room(String.t()) :: Room.t() + def create_room(name) do + end + + @spec join_room(String.t(), String.t()) :: Room.t() + def join_room(name, password) do + end + + def pass_card(state, player, to) do + end + + def keep_card(player) do + end + + def discard_card(player) do + end + + def turn_to_fake(player, card) do + end + + def cancel_player(player, target) do + end + + def viral_spiral(player, targets) do + end end diff --git a/lib/viral_spiral/game/room.ex b/lib/viral_spiral/game/room.ex index 4acb1a7..44e23b4 100644 --- a/lib/viral_spiral/game/room.ex +++ b/lib/viral_spiral/game/room.ex @@ -1,8 +1,18 @@ defmodule ViralSpiral.Game.Room do + alias ViralSpiral.Game.Room + defstruct id: "", name: "", state: :uninitialized + @type states :: :uninitialized | :waiting_for_players | :running | :paused + + @type t() :: %__MODULE__{ + id: String.t(), + name: String.t(), + state: states() + } + def new() do %__MODULE__{ id: UXID.generate!(prefix: "room", size: :small) diff --git a/lib/viral_spiral/game/round.ex b/lib/viral_spiral/game/round.ex index cca8892..e7e601c 100644 --- a/lib/viral_spiral/game/round.ex +++ b/lib/viral_spiral/game/round.ex @@ -32,6 +32,13 @@ defmodule ViralSpiral.Game.Round do current: 0, skip: nil + @type t :: %__MODULE__{ + order: list(String.t()), + count: integer(), + current: integer(), + skip: boolean() + } + @doc """ todo : this doesn't really need the players, merely a count of players, maybe? """ @@ -101,7 +108,4 @@ defmodule ViralSpiral.Game.Round do Map.merge(round, changes) end - - def current_id() do - end end diff --git a/lib/viral_spiral/game/state.ex b/lib/viral_spiral/game/state.ex new file mode 100644 index 0000000..132455a --- /dev/null +++ b/lib/viral_spiral/game/state.ex @@ -0,0 +1,27 @@ +defmodule ViralSpiral.Game.State do + defstruct room: nil, + player_list: nil, + player_map: nil, + scores: nil, + round: nil, + turn: nil + + @moduledoc """ + Context for the game. + + Rounds and Turns + round = Round.new(players) + round_order = Round.order(round) + During a Round every player gets to draw a card and then take some actions. + When a round begins, we also start a Turn. Within each Round there's a turn that includes everyone except the person who started the turn. + """ + alias ViralSpiral.Game.State + + def set_round(%State{} = game, round) do + %State{game | round: round} + end + + def set_turn(%State{} = game, turn) do + %State{game | turn: turn} + end +end diff --git a/test/support/fixtures.ex b/test/support/fixtures.ex index 6ba74da..815b52a 100644 --- a/test/support/fixtures.ex +++ b/test/support/fixtures.ex @@ -1,7 +1,7 @@ defmodule Fixtures do alias ViralSpiral.Game.Player alias ViralSpiral.Game.Room - alias ViralSpiral.Game + alias ViralSpiral.Game.State def initialized_game() do player_list = [ @@ -13,7 +13,7 @@ defmodule Fixtures do players = Enum.reduce(player_list, %{}, fn player, acc -> Map.put(acc, player.id, player) end) - %Game{ + %State{ room: Room.new(), player_map: players, player_list: player_list