models

package
v0.0.0-...-d26b62e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Clubs    = 0
	Diamonds = 1
	Hearts   = 2
	Spades   = 3
)

Colors of the card

Variables

This section is empty.

Functions

This section is empty.

Types

type Bank

type Bank interface {
	GetPlayerWallet(string) *money.Money
	GetMaxBet(string) *money.Money
}

type Card

type Card struct {
	Color int `json:"color" mapstructure:"color"`
	Value int `json:"value" mapstructure:"value"`
}

Card represents a play card which has a color and a value Values: [0,2];[1,3];[2,4];[3,5];[4,6];[5,7];[6,8];[7,9];[8,10];[9,J];[10,Q];[11,K];[12,A]

func GetRandom

func GetRandom() (*Card, error)

GetRandom picks a random card with an equal chance

func NewCard

func NewCard(color, value int) (*Card, error)

NewCard creates a card from the color and value given

func (*Card) String

func (card *Card) String() string

func (Card) Validate

func (card Card) Validate() error

Validate validates the color and the value of the card.

type Event

type Event struct {
	Name string      `json:"event"`
	Data interface{} `json:"data"`
}

func NewEvent

func NewEvent(name string, data interface{}) *Event

func NewEventFromRaw

func NewEventFromRaw(raw []byte) (*Event, error)

func (*Event) ToRaw

func (e *Event) ToRaw() []byte

type Player

type Player struct {
	//ID the id of the player. should be unique
	ID string `json:"id" mapstructure:"buyin"`
	//Username the username
	Username string `json:"username" mapstructure:"buyin"`
	//BuyIn buy in
	BuyIn *money.Money `json:"buyin" mapstructure:"buyin"`
	//Out channel to the outside. Will be send over websocket.
	Out chan []byte
	//In channel is the incoming channel over the websocket conn.
	In chan *Event
	//Active active
	Active bool
	//Close channel will be closed when player leaves
	Close chan bool
	//Left determins if the player already quitted but is in an active round
	Left bool
}

func NewPlayer

func NewPlayer(username, id string, buyin int, in chan *Event, out chan []byte, close chan bool) *Player

func (*Player) String

func (p *Player) String() string

func (*Player) ToPublic

func (p *Player) ToPublic() *PublicPlayer

func (*Player) ToPublicWithWallet

func (p *Player) ToPublicWithWallet(b Bank) *PublicPlayer

type PublicPlayer

type PublicPlayer struct {
	Username string  `json:"username" mapstructure:"username"`
	ID       string  `json:"id" mapstructure:"id"`
	BuyIn    string  `json:"buyIn" mapstructure:"buyIn"`
	BuyInNum float64 `json:"buyInNum" mapstructure:"buyInNum"`
}

func (*PublicPlayer) SetBuyIn

func (p *PublicPlayer) SetBuyIn(buyIn string, buyInNum float64)

func (*PublicPlayer) String

func (p *PublicPlayer) String() string

Jump to

Keyboard shortcuts

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