Compare commits

..

4 Commits

6 changed files with 62 additions and 17 deletions

2
.gitignore vendored
View File

@ -1 +1 @@
builds builds

18
.pre-commit-config.yaml Normal file
View 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
View 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

View File

@ -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

View File

@ -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) {

View File

@ -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,
}, },
}, },