View Source Buzzword.Bingo.Square (Buzzword Bingo Square v0.1.35)

A square struct and functions for the Multi-Player Buzzword Bingo game.

The square struct contains the fields phrase, points and marked_by representing the properties of a square in the Multi-Player Buzzword Bingo game.

Based on the course Multi-Player Bingo by Mike and Nicole Clark.

Summary

Types

Square phrase

Square points

t()

A square struct for the Multi-Player Buzzword Bingo game

Functions

Marks a virgin square having the given phrase with the given player.

Creates a square struct from the given buzzword.

Creates a square struct from the given phrase and points.

Types

phrase()

@type phrase() :: String.t()

Square phrase

points()

@type points() :: pos_integer()

Square points

t()

@type t() :: %Buzzword.Bingo.Square{
  marked_by: Buzzword.Bingo.Player.t() | nil,
  phrase: phrase(),
  points: points()
}

A square struct for the Multi-Player Buzzword Bingo game

Functions

mark(square, phrase, player)

@spec mark(t(), phrase(), Buzzword.Bingo.Player.t()) :: t()

Marks a virgin square having the given phrase with the given player.

Examples

iex> alias Buzzword.Bingo.{Player, Square}
iex> square = Square.new("Bottom Line", 375)
iex> arthur = Player.new("Arthur", "green_yellow")
iex> Square.mark(square, "Bottom Line", arthur)
%Square{
  phrase: "Bottom Line",
  points: 375,
  marked_by: %Player{name: "Arthur", color: "green_yellow"}
}

iex> alias Buzzword.Bingo.{Player, Square}
iex> square = Square.new("Big Picture", 225)
iex> arnold = Player.new("Arnold", "bright_turquoise")
iex> Square.mark(square, "Best of Breed", arnold)
%Square{phrase: "Big Picture", points: 225, marked_by: nil}

iex> alias Buzzword.Bingo.{Player, Square}
iex> square = Square.new("Best of Breed", 525)
iex> joe = Player.new("Joe", "light_cyan")
iex> jim = Player.new("Jim", "light_yellow")
iex> square = Square.mark(square, "Best of Breed", joe)
iex> Square.mark(square, "Best of Breed", jim)
%Square{
  phrase: "Best of Breed",
  points: 525,
  marked_by: %Player{name: "Joe", color: "light_cyan"}
}

new(buzzword)

@spec new(Buzzword.Cache.buzzword()) :: t() | {:error, atom()}

Creates a square struct from the given buzzword.

Examples

iex> alias Buzzword.Bingo.Square
iex> Square.new({"Bottom Line", 375})
%Square{phrase: "Bottom Line", points: 375}

iex> alias Buzzword.Bingo.Square
iex> Square.new({"Bottom Line", 0})
{:error, :invalid_square_args}

new(phrase, points)

@spec new(phrase(), points()) :: t() | {:error, atom()}

Creates a square struct from the given phrase and points.

Examples

iex> alias Buzzword.Bingo.Square
iex> Square.new("Bottom Line", 375)
%Square{phrase: "Bottom Line", points: 375}

iex> alias Buzzword.Bingo.Square
iex> Square.new("Bottom Line", 0)
{:error, :invalid_square_args}