bomb

package
v0.0.0-...-839ea1c Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMinPlayers = Error{

		ErrCode: MinPlayers,
		// contains filtered or unexported fields
	}
	ErrPartyNotReady = Error{

		ErrCode: PartyNotReady,
		// contains filtered or unexported fields
	}
	ErrPartyAlreadyStarted = Error{

		ErrCode: PartyAlreadyStarted,
		// contains filtered or unexported fields
	}
	ErrPartyOver = Error{

		ErrCode: PartyOver,
		// contains filtered or unexported fields
	}
	ErrTooManyPlayers = Error{

		ErrCode: TooManyPlayers,
		// contains filtered or unexported fields
	}
	ErrPlayerNotFound = Error{

		ErrCode: PlayerNotFound,
		// contains filtered or unexported fields
	}
	ErrTargetNotFound = Error{

		ErrCode: TargetNotFound,
		// contains filtered or unexported fields
	}
	ErrNotYourTurn = Error{

		ErrCode: NotYourTurn,
		// contains filtered or unexported fields
	}
	ErrCardNotFound = Error{

		ErrCode: CardNotFound,
		// contains filtered or unexported fields
	}
	ErrCannotDrawSelf = Error{

		ErrCode: CannotDrawSelf,
		// contains filtered or unexported fields
	}
)

game errors

Functions

This section is empty.

Types

type Card

type Card uint8

Card type

const (
	Unkown Card = iota
	// No effect card
	Safe
	// Victory condition
	Defuse
	// Game over condition
	Bomb
	// Card already drawn another round
	Drawn
)

enum kinds of cards

type ErrCode

type ErrCode uint8

ErrCode type

const (
	Nothing ErrCode = iota
	MinPlayers
	PartyNotReady
	PartyAlreadyStarted
	PartyOver
	TooManyPlayers
	PlayerNotFound
	TargetNotFound
	NotYourTurn
	CardNotFound
	CannotDrawSelf // cannot draw from your own hand
)

enum kinds of error codes

type Error

type Error struct {
	ErrCode
	// contains filtered or unexported fields
}

Error type implements error and adds a code information to be used by a client/frontend. Useful for i18n

func (Error) Error

func (e Error) Error() string

type Game

type Game struct {
	// contains filtered or unexported fields
}

Game contains the state

func New

func New() Game

New creates a Bomb game

func (*Game) GetState

func (g *Game) GetState(id int64) (PlayerState, error)

GetState build the visible state by the player

func (*Game) Join

func (g *Game) Join(id int64) error

Join adds the player to the game

func (*Game) Play

func (g *Game) Play(id int64, m Move) error

Play a move

func (*Game) SetReady

func (g *Game) SetReady(id int64, b bool)

SetReady changes the status of readiness

type Move

type Move struct {
	Target     int64
	CardToDraw uint8
}

Move is a play action

type PlayerState

type PlayerState struct {
	Cards         []Card    // shuffled hand of the player
	Players       []int64   // all players' ids
	Readies       []bool    // who's ready
	Playing       int64     // who's playing
	Round         uint8     // current round
	CardsRevealed uint8     // cards revealed this round / turn counter
	DefusesFound  uint8     // win condition of Heroes
	Role          Role      // team of the player
	State         StateKind // party's state
	Winner        Role
}

PlayerState contains the state visible by the player

type Role

type Role uint8

Role type

const (
	None Role = iota
	Hero
	Vilain
)

enum kinds of players

type StateKind

type StateKind uint8

StateKind type

const (
	Lobby StateKind = iota
	Running
	Over
)

enum kinds of players

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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