models

package
v0.0.0-...-73d33f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SuitClubs    = Suit("CLUBS")
	SuitDiamonds = Suit("DIAMONDS")
	SuitHearts   = Suit("HEARTS")
	SuitSpades   = Suit("SPADES")

	ValueAce   = Value("ACE")
	ValueJack  = Value("JACK")
	ValueQueen = Value("QUEEN")
	ValueKing  = Value("KING")
)

Variables

View Source
var (
	ErrCardCodeValueInvalid = errors.New("card code value is invalid")
	ErrCardCodeSuitInvalid  = errors.New("card code suit is invalid")
)
View Source
var (
	ErrNotEnoughCards = errors.New("there is not enough cards in the deck for the operation")
	ErrDeckOpened     = errors.New("not permitted on opened deck")
	ErrNotFound       = errors.New("resource not found")
	ErrUUIDRequired   = errors.New("uuid is required")
	ErrUUIDInvalid    = errors.New("uuid is not valid")
)

Functions

This section is empty.

Types

type Card

type Card struct {
	Value Value  `json:"value"`
	Suit  Suit   `json:"suit"`
	Code  string `json:"code"`
}

Card representation of Card

func NewCard

func NewCard(value Value, suit Suit) *Card

NewCard returns new card instance

type CardService

type CardService interface {
	CardStorage
	ByCodesStr(codesStr string) ([]*Card, error)
}

func NewCardService

func NewCardService() CardService

NewCardService returns new CardService instance

type CardStorage

type CardStorage interface {
	// ByCode is used to retrieve single card by code
	ByCode(code string) (*Card, error)
	// All is used to retrieve all cards
	All() ([]*Card, error)
}

CardStorage is used to interact with cards storage

type Deck

type Deck struct {
	UUID      string  `json:"deck_id"`
	Shuffled  bool    `json:"shuffled"`
	Remaining int     `json:"remaining"`
	Cards     []*Card `json:"cards"`
	CardCodes string  `json:"-"`
	Opened    bool    `json:"-"`
}

Deck is the representation of deck of cards

type DeckService

type DeckService interface {
	DeckStorage
	Draw(deck *Deck, count int) ([]*Card, error)
	Open(deck *Deck) error
}

func NewDeckService

func NewDeckService(cs CardService) DeckService

NewDeckService returns deckService instance by defaults

type DeckStorage

type DeckStorage interface {
	Create(deck *Deck) error
	ByUUID(uuid string) (*Deck, error)
	Update(deck *Deck) error
}

type Suit

type Suit string

func (Suit) Code

func (s Suit) Code() string

Code returns first character of suit as code

type Value

type Value string

func (Value) Code

func (v Value) Code() string

Code returns first character of value if value is not numeric returns value if numeric

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL