Documentation ¶
Index ¶
Constants ¶
const ( DifficultyClassic = iota DifficultyBeginner = iota DifficultyIntermediate = iota DifficultyExpert = iota )
const ( DifficultyRowColMin = 8 DifficultyRowColMax = 99 DifficultyMineMin = 9 DifficultyMineMaxPercentage = 0.8 )
Variables ¶
This section is empty.
Functions ¶
func NewErrDifficultyDimension ¶ added in v0.2.0
func NewErrDifficultyMineCount ¶ added in v0.2.0
Types ¶
type Difficulty ¶
Represent a difficulty setting for the Game
func Difficulties ¶
func Difficulties() []Difficulty
Exposes pre-defined difficulties in a way that does not allow the original array to be modified
func NewCustomDifficulty ¶ added in v0.2.0
func NewCustomDifficulty(mines, row, col int) (Difficulty, error)
type ErrDifficultyDimension ¶ added in v0.2.0
type ErrDifficultyDimension struct {
// contains filtered or unexported fields
}
func (*ErrDifficultyDimension) Error ¶ added in v0.2.0
func (e *ErrDifficultyDimension) Error() string
type ErrDifficultyMineCount ¶ added in v0.2.0
type ErrDifficultyMineCount struct {
// contains filtered or unexported fields
}
func (*ErrDifficultyMineCount) Error ¶ added in v0.2.0
func (e *ErrDifficultyMineCount) Error() string
type Field ¶
type Field struct { Checked bool Content FieldContent }
Represents a single field in a minefield
type FieldContent ¶
type FieldContent int
Represents the content of a field. Can be a mine, unknown or the number of mines in the neighboring fields
const ( Mine FieldContent = -1 Unknown FieldContent = -2 )
type Game ¶
type Game interface { // Check a given field and recursevly reveal all neighboring fields that should be revield. // Returns the resulting new status of the game CheckField(p Pos) *Status // Recursive function to reveal all neighbouring fields that can be safely reveald. // Stops when a field has not exactly zero neighbouring mines RevealField(p Pos) // Check if the given position is out of bounds OutOfBounds(p Pos) bool // Returns the current status of the game. Only contains the knowledge a player should have. Status() *Status // Check if Game Over Lost() bool // Check if the game is won Won() bool // Reset the current game to be played again Replay() // Check if the game is a replay IsReplay() bool }
Interface for playing the game
type LocalGame ¶ added in v0.2.0
type LocalGame struct { Field [][]Field Difficulty Difficulty // Keep these 2 exported for testing in other packages GameOver bool GameWon bool // contains filtered or unexported fields }
func NewGameWithSafePos ¶
func NewGameWithSafePos(d Difficulty, p Pos) *LocalGame
Create a new game with mines seeded randomly in the map, with the exception of the given position.
func (*LocalGame) CheckField ¶ added in v0.2.0
Check a given field and recursevly reveal all neighboring fields that should be revield. Returns the resulting new status of the game
func (*LocalGame) OutOfBounds ¶ added in v0.2.0
Check if the given position is out of bounds
func (*LocalGame) Replay ¶ added in v0.2.0
func (g *LocalGame) Replay()
Reset the current game to be played again
func (*LocalGame) RevealField ¶ added in v0.2.0
Recursive function to reveal all neighbouring fields that can be safely reveald. Stops when a field has not exactly zero neighbouring mines
type Pos ¶
type Pos struct {
X, Y int
}
Represent a position in the minefield
func CreateMines ¶
func CreateMines(d Difficulty, p Pos) []Pos
Randomly create mines for the given difficulty. Does not create a mine on the given position.