regeda / minesweeper

Golang implementation of Minesweeper game API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minesweeper

Golang implementation of Minesweeper game API.

cols := 5
rows := 5
difficulty := 0.3 // how much mines should be generated ceil(cols*rows*difficulty)

m := minesweeper.GenerateGrid(rows, cols, difficulty)
g := minesweeper.New(m)

for {
	// ... read i,j
	// you can set a flag
	m[i][j].Flag(true)
	// or unset
	m[i][j].Flag(false)
	// or unfold a cell
	left, ok := g.Unfold(i, j)
	if !ok {
		// game over, you touched a mine
	} else if left == 0 {
		// you won, all free cells unfolded
	}
}

Or play in command line:

go run cmd/minesweeper/main.go

About

Golang implementation of Minesweeper game API

License:MIT License


Languages

Language:Go 100.0%