engine

package
v0.0.0-...-e9bd53e Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GameMinRows         = 3
	GameMinCols         = 3
	GameMaxRows         = 50
	GameMaxCols         = 50
	GameStatusCreated   = "created"
	GameStatusStarted   = "started"
	GameStatusVictory   = "victory"
	GameStatusDefeat    = "defeat"
	GameClickTypeNormal = 1
	GameClickTypeFlag   = 2
	GameClickTypeReveal = 3
)

Some default game parameters, if the user does not provide those.

Variables

View Source
var (
	ErrDefeat    = errors.New("Defeat")
	ErrNotActive = errors.New("Game not active")
)

Functions

This section is empty.

Types

type ClickType

type ClickType int

type Field

type Field struct {
	Mine      bool     `json:"mine"`
	Clicked   bool     `json:"clicked"`   // indicated whether the field was clicked
	Flagged   bool     `json:"flagged"`   // red flag in the field
	AdjCount  int      `json:"adjMines"`  // count of adjacent mines
	Position  Position `json:"position"`  // position in the minefield
	ClickedBy string   `json:"clickedBy"` // who clicked this field
}

Field represents a square unit in the MineField

type Game

type Game struct {
	ID         string     `json:"id"`
	Rows       int        `json:"rows"`
	Cols       int        `json:"cols"`
	Mines      int        `json:"mines"`
	Status     GameStatus `json:"status"`
	MineField  [][]Field  `json:"mineField"`
	StartedAt  *time.Time `json:"startedAt,omitempty"`
	FinishedAt *time.Time `json:"finishedAt,omitempty"`
	CreatedAt  time.Time  `json:"createdAt"`
	CreatedBy  string     `json:"createdBy"` // who created this game
}

Game contains the structure of the game

func NewGame

func NewGame(rows, cols, mines int, createdBy string) *Game

func (*Game) Click

func (g *Game) Click(clickedBy string, clickType ClickType, row, col int) error

func (*Game) IsActive

func (g *Game) IsActive() bool

func (*Game) Start

func (g *Game) Start() error

type GameStatus

type GameStatus string

type Position

type Position struct {
	Row int `json:"row"` // row of the field position
	Col int `json:"col"` // col of the field position
}

Position stores the position of the field in the board

Jump to

Keyboard shortcuts

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