From 6d23349e430a6aae22333e9fe0f06b1a61c3fccd Mon Sep 17 00:00:00 2001 From: Sacha Ligthert Date: Wed, 5 Mar 2025 12:05:49 +0100 Subject: [PATCH] Redo how a string is pushed into an array of runes and then printed. (Closes #11) --- render.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/render.go b/render.go index 0eb89e1..681fa8e 100644 --- a/render.go +++ b/render.go @@ -9,20 +9,24 @@ import ( // drawScore Print the score func drawScore(screen tcell.Screen, style tcell.Style, score *Score) { var x, y int = 5, 24 - for _, r := range []rune("[ Score: " + strconv.FormatInt(int64(score.score), 10) + " ]") { - screen.SetContent(x, y-1, r, nil, style) + 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 - for _, r := range []rune("[ x:" + strconv.FormatInt(int64(*&snake.head.x), 10) + " y: " + strconv.FormatInt(int64(*&snake.head.y), 10) + " ]") { - screen.SetContent(x, y-1, r, nil, style) - x++ - } -} +// 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) {