Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
6d23349e43 | |||
feced4cd7f | |||
76b6150a1e | |||
b7af5b64ad |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
|||||||
builds
|
builds
|
||||||
|
18
.pre-commit-config.yaml
Normal file
18
.pre-commit-config.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# See https://pre-commit.com for more information
|
||||||
|
# See https://pre-commit.com/hooks.html for more hooks
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v5.0.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-yaml
|
||||||
|
- id: check-added-large-files
|
||||||
|
- repo: https://github.com/dnephin/pre-commit-golang
|
||||||
|
rev: v0.5.1
|
||||||
|
hooks:
|
||||||
|
- id: go-fmt
|
||||||
|
- id: go-imports
|
||||||
|
- id: no-go-testing
|
||||||
|
- id: golangci-lint
|
||||||
|
- id: go-unit-tests
|
28
Taskfile.dist.yaml
Normal file
28
Taskfile.dist.yaml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
vars:
|
||||||
|
APP: snake
|
||||||
|
BUILD_DIR: builds
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
default:
|
||||||
|
cmds:
|
||||||
|
- go run .
|
||||||
|
build:
|
||||||
|
cmds:
|
||||||
|
- mkdir -p {{.BUILD_DIR}}
|
||||||
|
- rm {{.BUILD_DIR}}/* || true
|
||||||
|
- go tool dist list | grep -v android | grep -v ios | grep -v wasip1 | awk -F '/' '{printf "echo Compiling %s/%s; env CGO_ENABLED=1 GOOS=%s GOARCH=%s go build -o {{.BUILD_DIR}}/{{.APP}}.%s-%s\n",$1,$2,$1,$2,$1,$2 }' | sh
|
||||||
|
- for i in `ls {{.BUILD_DIR}}/*windows*`; do mv -v $i $i.exe; done
|
||||||
|
lint:
|
||||||
|
cmds:
|
||||||
|
- golangci-lint run
|
||||||
|
precommit:
|
||||||
|
cmds:
|
||||||
|
- pre-commit autoupdate
|
||||||
|
- pre-commit run --all
|
||||||
|
silent: true
|
||||||
|
gource:
|
||||||
|
cmds:
|
||||||
|
- gource --auto-skip-seconds 1 --key -r 60
|
||||||
|
silent: true
|
5
build.sh
5
build.sh
@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
mkdir -p builds
|
|
||||||
|
|
||||||
go tool dist list | grep -v android | grep -v darwin | grep -v ios | grep -v wasip1 | awk -F '/' '{printf "echo Compiling %s/%s; env CGO_ENABLED=1 GOOS=%s GOARCH=%s go build -o builds/snake.%s-%s\n",$1,$2,$1,$2,$1,$2 }' | sh
|
|
22
render.go
22
render.go
@ -9,20 +9,24 @@ import (
|
|||||||
// drawScore Print the score
|
// drawScore Print the score
|
||||||
func drawScore(screen tcell.Screen, style tcell.Style, score *Score) {
|
func drawScore(screen tcell.Screen, style tcell.Style, score *Score) {
|
||||||
var x, y int = 5, 24
|
var x, y int = 5, 24
|
||||||
for _, r := range []rune("[ Score: " + strconv.FormatInt(int64(score.score), 10) + " ]") {
|
content := "[ Score: " + strconv.FormatInt(int64(score.score), 10) + " ]"
|
||||||
screen.SetContent(x, y-1, r, nil, style)
|
for i := 0; i < len(content); i++ {
|
||||||
|
screen.SetContent(x, y-1, rune(content[i]), nil, style)
|
||||||
x++
|
x++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// drawCoords Print the coordinates of the head of the snake
|
// drawCoords Print the coordinates of the head of the snake
|
||||||
func drawCoords(screen tcell.Screen, style tcell.Style, snake *Snake) {
|
// func drawCoords(screen tcell.Screen, style tcell.Style, snake *Snake) {
|
||||||
var x, y int = 25, 24
|
// var x, y int = 25, 24
|
||||||
for _, r := range []rune("[ x:" + strconv.FormatInt(int64(*&snake.head.x), 10) + " y: " + strconv.FormatInt(int64(*&snake.head.y), 10) + " ]") {
|
// var snakex int = *&snake.head.x
|
||||||
screen.SetContent(x, y-1, r, nil, style)
|
// var snakey int = *&snake.head.y
|
||||||
x++
|
// content := "[ x:" + strconv.Itoa(snakex) + " y: " + strconv.Itoa(snakey) + " ]"
|
||||||
}
|
// for i := 0; i < len(content); i++ {
|
||||||
}
|
// screen.SetContent(x, y-1, rune(content[i]), nil, style)
|
||||||
|
// x++
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// drawBox Draw the outline of the box the snake can move in
|
// drawBox Draw the outline of the box the snake can move in
|
||||||
func drawBox(s tcell.Screen, style tcell.Style, x1, y1, x2, y2 int) {
|
func drawBox(s tcell.Screen, style tcell.Style, x1, y1, x2, y2 int) {
|
||||||
|
4
snake.go
4
snake.go
@ -14,7 +14,7 @@ func initSnake(snakex int, snakey int) Snake {
|
|||||||
},
|
},
|
||||||
tail: []Position{
|
tail: []Position{
|
||||||
{
|
{
|
||||||
x: x - 1,
|
x: x - 3,
|
||||||
y: y,
|
y: y,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -22,7 +22,7 @@ func initSnake(snakex int, snakey int) Snake {
|
|||||||
y: y,
|
y: y,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
x: x - 3,
|
x: x - 1,
|
||||||
y: y,
|
y: y,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user