minesweeper

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 5 Imported by: 0

README

Minesweeper

Play minesweeper in the terminal!

demo

Install

Go:

go install github.com/bhb603/minesweeper/cmd/minesweeper-cli@latest

Docker:

docker pull ghcr.io/bhb603/minesweeper

Usage

minesweeper-cli

Docker:

docker run --rm -it ghcr.io/bhb603/minesweeper-cli

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	X        int
	Y        int
	Revealed bool
	Flagged  bool
	AdjMines int
	Type     CellType
}

func NewCell

func NewCell(cellType CellType, x, y int) (*Cell, error)

func (*Cell) AdjacentCells

func (c *Cell) AdjacentCells(grid [][]*Cell) []*Cell

func (*Cell) Reveal

func (c *Cell) Reveal()

func (Cell) String

func (c Cell) String() string

func (*Cell) ToggleFlag

func (c *Cell) ToggleFlag() error

type CellType

type CellType int
const (
	CellTypeMine CellType = iota
	CellTypeAdjacent
)

type Game

type Game struct {
	ID         string `json:"id"`
	Grid       [][]*Cell
	Status     GameStatus
	NumFlagged int
	GameConfig
}

func NewGame

func NewGame(config GameConfig) *Game

func (*Game) GetCell

func (g *Game) GetCell(x, y int) (*Cell, error)

func (*Game) RevealAdj

func (g *Game) RevealAdj(x, y int) ([]*Cell, error)

func (*Game) RevealCell

func (g *Game) RevealCell(x, y int) ([]*Cell, error)

func (*Game) ToggleFlag

func (g *Game) ToggleFlag(x, y int) ([]*Cell, error)

type GameConfig

type GameConfig struct {
	Height   int
	Width    int
	NumMines int
}
var (
	Beginner     GameConfig = GameConfig{8, 8, 10}
	Intermediate GameConfig = GameConfig{16, 16, 40}
	Expert       GameConfig = GameConfig{24, 24, 99}
)

type GameStatus

type GameStatus int
const (
	GameStatusLost GameStatus = iota
	GameStatusWon
	GameStatusInProgress
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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