-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cf58eec
Showing
31 changed files
with
1,486 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior. Code samples if possible. | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Software (please complete the following information):** | ||
- OS: [e.g. OSX] | ||
- GoLang Version [e.g. 1.10] | ||
|
||
**Additional context** | ||
Add any other context about the problem here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Feature request | ||
about: Suggest an idea for this project | ||
|
||
--- | ||
|
||
**Is your feature request related to a problem? Please describe.** | ||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] | ||
|
||
**Describe the solution you'd like** | ||
A clear and concise description of what you want to happen. | ||
|
||
**Describe alternatives you've considered** | ||
A clear and concise description of any alternative solutions or features you've considered. | ||
|
||
**Additional context** | ||
Add any other context or screenshots about the feature request here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## Proposed Changes | ||
- | ||
- | ||
- | ||
|
||
Fixes #<insert Issue # here if applicable>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: CD | ||
|
||
on: | ||
# Versioned Tags | ||
push: | ||
tags: | ||
- "v*.*.*" | ||
|
||
jobs: | ||
# Build and test everything | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Checkout the code | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
|
||
# Set up the GoLang environment | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
|
||
# Download all the tools used in the steps that follow | ||
- name: Set up Tools | ||
run: | | ||
make get-tools | ||
# Run all the unit-tests | ||
- name: Test | ||
run: | | ||
make test | ||
# Build all the binaries for upload | ||
- name: Build Binaries | ||
run: | | ||
make dist | ||
# Release binaries | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: | | ||
dist/go-mines* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: CI | ||
|
||
on: | ||
# Pushes and pulls to all branches | ||
push: | ||
pull_request: | ||
|
||
# Run on the first day of every month | ||
schedule: | ||
- cron: "0 0 1 * *" | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
# Build and test everything | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Checkout the code | ||
- name: Checkout Code | ||
uses: actions/checkout@v2 | ||
|
||
# Set up the GoLang environment | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18 | ||
|
||
# Download all the tools used in the steps that follow | ||
- name: Set up Tools | ||
run: | | ||
make get-tools | ||
# Run all the unit-tests | ||
- name: Test | ||
run: | | ||
make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.csv | ||
*.swp | ||
.coverprofile | ||
/.idea/ | ||
/dist | ||
/go-mines | ||
/go-mines.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 jedib0t | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.PHONY: all test dist | ||
|
||
VERSION ?= dev | ||
ifdef GITHUB_REF_NAME | ||
VERSION = $(GITHUB_REF_NAME) | ||
endif | ||
|
||
|
||
default: run | ||
|
||
all: test | ||
|
||
build: | ||
go build ./cmd/go-mines | ||
|
||
demo: build | ||
./go-mines | ||
|
||
dist: | ||
gox -ldflags="-s -w -X main.version=${VERSION}" \ | ||
-os="linux darwin windows" \ | ||
-arch="amd64" \ | ||
-output="./dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \ | ||
./cmd/go-mines | ||
|
||
fmt: tidy | ||
go fmt $(shell go list ./...) | ||
|
||
get-tools: | ||
go install github.com/mitchellh/[email protected] | ||
go install golang.org/x/lint/golint@latest | ||
|
||
lint: | ||
golint -set_exit_status $(shell go list ./...) | ||
|
||
run: | ||
go run . | ||
|
||
test: fmt lint vet build | ||
go test -cover -coverprofile=.coverprofile ./digital ./minefield | ||
|
||
tidy: | ||
go mod tidy | ||
|
||
vet: | ||
go vet $(shell go list ./...) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# go-mines | ||
|
||
[![Build Status](https://github.com/jedib0t/go-mines/workflows/CI/badge.svg?branch=main)](https://github.com/jedib0t/go-mines/actions?query=workflow%3ACI+event%3Apush+branch%3Amain) | ||
|
||
An implementation of Minesweeper for the command-line in GoLang. | ||
|
||
# Install | ||
|
||
You can download the latest release for your OS [here](https://github.com/jedib0t/go-mines/releases/latest). | ||
|
||
### Using GoLang | ||
``` | ||
go install github.com/jedib0t/go-mines/cmd/go-mines | ||
``` | ||
|
||
# Sample | ||
|
||
<img src="mines.png" alt="Sample" width="480"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
func handleActionQuit() { | ||
userQuit = true | ||
} | ||
|
||
func handleActionReset() { | ||
renderMutex.Lock() | ||
defer renderMutex.Unlock() | ||
|
||
generateMineField() | ||
} | ||
|
||
func handleActionInput(char rune) { | ||
renderMutex.Lock() | ||
defer renderMutex.Unlock() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"time" | ||
) | ||
|
||
var ( | ||
flagHelp = flag.Bool("help", false, "Show this help-text?") | ||
flagNumCols = flag.Int("cols", numRows, fmt.Sprintf("Number of Columns (max: %d)", maxCols)) | ||
flagNumMines = flag.Int("mines", numMines, "Number of Mines (max: 50% of grid)") | ||
flagNumRows = flag.Int("rows", numCols, fmt.Sprintf("Number of Rows (max: %d)", maxRows)) | ||
flagRefreshRate = flag.Int("refresh-rate", 20, "Refresh-rate per second") | ||
flagSeed = flag.Int64("seed", 0, "Randomizer Seed value (will use current time if ZERO)") | ||
flagWin = flag.Bool("win", false, "Cheat and Win?") | ||
) | ||
|
||
func initFlags() { | ||
flag.Parse() | ||
if *flagHelp { | ||
printHelp() | ||
} | ||
|
||
// control rows/cols | ||
if *flagNumCols > maxCols { | ||
*flagNumCols = maxCols | ||
} | ||
if *flagNumRows > maxRows { | ||
*flagNumRows = maxRows | ||
} | ||
if (*flagNumCols != numCols || *flagNumRows != numRows) && *flagNumMines == numMines { | ||
*flagNumMines = roundToNearest10th(*flagNumRows * *flagNumCols / 5) | ||
} | ||
if *flagNumMines > (*flagNumRows**flagNumCols)/2 { | ||
*flagNumMines = roundToNearest10th((*flagNumRows * *flagNumCols) / 2) | ||
} | ||
if *flagSeed == 0 { | ||
*flagSeed = time.Now().Unix() | ||
} | ||
rand.Seed(*flagSeed) | ||
} | ||
|
||
func printHelp() { | ||
fmt.Println(`go-mines: A GoLang implementation of the Minesweeper game. | ||
Version: ` + version + ` | ||
Flags | ||
=====`) | ||
flag.PrintDefaults() | ||
os.Exit(0) | ||
} |
Oops, something went wrong.