2023-11-06 23:44:17 +01:00
|
|
|
package main
|
|
|
|
|
2023-11-07 21:47:32 +01:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
)
|
2023-11-06 23:44:17 +01:00
|
|
|
|
2023-11-23 23:28:44 +01:00
|
|
|
// drawScore Print the score
|
2023-11-24 22:17:19 +01:00
|
|
|
func drawScore(screen tcell.Screen, style tcell.Style, score *Score) {
|
2023-11-12 14:51:06 +01:00
|
|
|
var x, y int = 5, 24
|
2023-11-24 22:17:19 +01:00
|
|
|
for _, r := range []rune("[ Score: " + strconv.FormatInt(int64(score.score), 10) + " ]") {
|
2023-11-07 21:47:32 +01:00
|
|
|
screen.SetContent(x, y-1, r, nil, style)
|
|
|
|
x++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-23 23:28:44 +01:00
|
|
|
// drawCoords Print the coordinates of the head of the snake
|
2023-11-23 22:36:44 +01:00
|
|
|
func drawCoords(screen tcell.Screen, style tcell.Style, snake *Snake) {
|
2023-11-12 14:51:06 +01:00
|
|
|
var x, y int = 25, 24
|
2023-11-23 22:36:44 +01:00
|
|
|
for _, r := range []rune("[ x:" + strconv.FormatInt(int64(*&snake.head.x), 10) + " y: " + strconv.FormatInt(int64(*&snake.head.y), 10) + " ]") {
|
2023-11-12 14:51:06 +01:00
|
|
|
screen.SetContent(x, y-1, r, nil, style)
|
|
|
|
x++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-23 23:28:44 +01:00
|
|
|
// drawBox Draw the outline of the box the snake can move in
|
2023-11-23 22:36:44 +01:00
|
|
|
func drawBox(s tcell.Screen, style tcell.Style, x1, y1, x2, y2 int) {
|
2023-11-07 21:47:32 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|