66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
)
|
|
|
|
// drawScore Print the score
|
|
func drawScore(screen tcell.Screen, style tcell.Style, score *Score) {
|
|
var x, y int = 5, 24
|
|
content := "[ Score: " + strconv.FormatInt(int64(score.score), 10) + " ]"
|
|
for i := 0; i < len(content); i++ {
|
|
screen.SetContent(x, y-1, rune(content[i]), nil, style)
|
|
x++
|
|
}
|
|
}
|
|
|
|
// drawCoords Print the coordinates of the head of the snake
|
|
// func drawCoords(screen tcell.Screen, style tcell.Style, snake *Snake) {
|
|
// var x, y int = 25, 24
|
|
// var snakex int = *&snake.head.x
|
|
// var snakey int = *&snake.head.y
|
|
// 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
|
|
func drawBox(s tcell.Screen, style tcell.Style, x1, y1, x2, y2 int) {
|
|
if y2 < y1 {
|
|
y1, y2 = y2, y1
|
|
}
|
|
if x2 < x1 {
|
|
x1, x2 = x2, x1
|
|
}
|
|
|
|
// Fill background
|
|
for row := y1; row <= y2; row++ {
|
|
for col := x1; col <= x2; col++ {
|
|
s.SetContent(col, row, ' ', nil, style)
|
|
}
|
|
}
|
|
|
|
// Draw borders
|
|
for col := x1; col <= x2; col++ {
|
|
s.SetContent(col, y1, '═', nil, style)
|
|
s.SetContent(col, y2, '═', nil, style)
|
|
}
|
|
for row := y1 + 1; row < y2; row++ {
|
|
s.SetContent(x1, row, '║', nil, style)
|
|
s.SetContent(x2, row, '║', nil, style)
|
|
}
|
|
|
|
// Only draw corners if necessary
|
|
if y1 != y2 && x1 != x2 {
|
|
s.SetContent(x1, y1, '╔', nil, style)
|
|
s.SetContent(x2, y1, '╗', nil, style)
|
|
s.SetContent(x1, y2, '╚', nil, style)
|
|
s.SetContent(x2, y2, '╝', nil, style)
|
|
}
|
|
|
|
}
|