Browse Source

Redo how a string is pushed into an array of runes and then printed. (Closes #11)

Sacha Ligthert 1 year ago
parent
commit
6d23349e43
1 changed files with 13 additions and 9 deletions
  1. 13 9
      render.go

+ 13 - 9
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) {