Skip to content

Commit

Permalink
chore: add type specs
Browse files Browse the repository at this point in the history
  • Loading branch information
dennyabrain committed Aug 14, 2024
1 parent 943295d commit 27133a3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 19 deletions.
42 changes: 28 additions & 14 deletions lib/viral_spiral/game.ex
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 6 in lib/viral_spiral/game.ex

View workflow job for this annotation

GitHub Actions / build-and-deploy

variable "name" is unused (if the variable is not meant to be used, prefix it with an underscore)
end

@spec join_room(String.t(), String.t()) :: Room.t()
def join_room(name, password) do

Check warning on line 10 in lib/viral_spiral/game.ex

View workflow job for this annotation

GitHub Actions / build-and-deploy

variable "name" is unused (if the variable is not meant to be used, prefix it with an underscore)
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
10 changes: 10 additions & 0 deletions lib/viral_spiral/game/room.ex
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 7 additions & 3 deletions lib/viral_spiral/game/round.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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?
"""
Expand Down Expand Up @@ -101,7 +108,4 @@ defmodule ViralSpiral.Game.Round do

Map.merge(round, changes)
end

def current_id() do
end
end
27 changes: 27 additions & 0 deletions lib/viral_spiral/game/state.ex
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/support/fixtures.ex
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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
Expand Down

0 comments on commit 27133a3

Please sign in to comment.