Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JocularMarrow committed Apr 7, 2023
1 parent 3537eb7 commit f64312f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
6 changes: 2 additions & 4 deletions internal/util/ansi.go → pkg/ansi.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package util
package minesweeper

import (
"regexp"
)
import "regexp"

var ansiEscapeCodes = `\x1B\[[0-?]*[ -/]*[@-~]`
var ansiRegex = regexp.MustCompile(ansiEscapeCodes)
Expand Down
10 changes: 4 additions & 6 deletions pkg/minesweeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"math/rand"
"reflect"

"github.com/TechMDW/minesweeper/internal/util"
)

// Cell represents a cell in a minesweeper board.
Expand Down Expand Up @@ -295,13 +293,13 @@ func (b *Board) Display(showMines bool) {

func (b *Board) Printf(format string, a ...any) {
if !*b.DisplayOptions.ANSI {
format = util.RemoveAnsiEscapeCodes(format)
format = RemoveAnsiEscapeCodes(format)

for i, v := range a {
t := reflect.TypeOf(v)

if t.Kind() == reflect.String {
a[i] = util.RemoveAnsiEscapeCodes(v.(string))
a[i] = RemoveAnsiEscapeCodes(v.(string))
} else {
a[i] = v
}
Expand All @@ -317,7 +315,7 @@ func (b *Board) Print(a ...any) {
t := reflect.TypeOf(v)

if t.Kind() == reflect.String {
a[i] = util.RemoveAnsiEscapeCodes(v.(string))
a[i] = RemoveAnsiEscapeCodes(v.(string))
} else {
a[i] = v
}
Expand All @@ -333,7 +331,7 @@ func (b *Board) Println(a ...any) {
t := reflect.TypeOf(v)

if t.Kind() == reflect.String {
a[i] = util.RemoveAnsiEscapeCodes(v.(string))
a[i] = RemoveAnsiEscapeCodes(v.(string))
} else {
a[i] = v
}
Expand Down
32 changes: 31 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,44 @@ Before getting started I recommend checking out the start flags by running `<bin
The game provides a simple command-line interface for playing Minesweeper. The board is displayed as a grid of cells, with row and column numbers as labels. The game supports the following commands:

- `r <row> <col>`: Reveal the cell at the specified row and column.
- `c <col> <row>`: Reveal the cell at the specified column and row
- `f <row> <col>`: Toggle a flag on or off at the specified row and column.
- `h`, `help`, `imlost`: Display the help message with a list of commands.
- `header`: Hide or show the header information.
- `footer`: Hide or show the footer information.
- `q`, `quit`, `exit`: Quit the game.
- `h`, `help`, `imlost`: Display the help message with a list of commands.

The game continues until all non-mine cells are revealed or a mine is revealed.

## Start flags

### Game options

- `-rows <int>`: Number of rows (default: 10)
- `-cols <int>`: Number of columns (default: 10)
- `-mines <int>`: Number of mines (default: 10)
- `-seed <int64>`: Seed for random number generator (default: current Unix timestamp in nanoseconds)

### Display options

- `-start <int>`: Start index (row and column start at this index, default: 1)
- `-ansi=<true|false>`: Use ANSI escape codes to color the board (default: true)

### Help

- `-h / -help`: Show help (default: false)

### Debug

- `-clear=<true|false>`: Automatically clear the screen (default: true)

### Example usage

1. `minesweeper -rows 10 -cols 20 -mines 30`
2. `minesweeper -h`
3. `minesweeper -ansi=false -clear=false -seed 50`
4. `minesweeper -rows 30 -ansi=false`

## Download prebuild package

1. Download the latest version of Minesweeper from the [GitHub releases page](https://github.com/myusername/minesweeper/releases/latest).
Expand Down

0 comments on commit f64312f

Please sign in to comment.