render.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package main
  2. import (
  3. "runtime"
  4. "strconv"
  5. )
  6. // drawBox Draw the outline of the box the snake can move in
  7. func (game *Game) drawBox() {
  8. // Assuming we will always have this
  9. x1 := 0
  10. y1 := 0
  11. x2 := 79
  12. y2 := 23
  13. // Fill background
  14. for row := y1; row <= y2; row++ {
  15. for col := x1; col <= x2; col++ {
  16. game.screen.SetContent(col, row, ' ', nil, game.style)
  17. }
  18. }
  19. // Draw borders
  20. for col := x1; col <= x2; col++ {
  21. game.screen.SetContent(col, y1, '═', nil, game.style)
  22. game.screen.SetContent(col, y2, '═', nil, game.style)
  23. }
  24. for row := y1 + 1; row < y2; row++ {
  25. game.screen.SetContent(x1, row, '║', nil, game.style)
  26. game.screen.SetContent(x2, row, '║', nil, game.style)
  27. }
  28. // Only draw corners if necessary
  29. if y1 != y2 && x1 != x2 {
  30. game.screen.SetContent(x1, y1, '╔', nil, game.style)
  31. game.screen.SetContent(x2, y1, '╗', nil, game.style)
  32. game.screen.SetContent(x1, y2, '╚', nil, game.style)
  33. game.screen.SetContent(x2, y2, '╝', nil, game.style)
  34. }
  35. }
  36. // drawCoords Print the coordinates of the player
  37. func (game *Game) drawCoords() {
  38. var x, y int = 25, 24
  39. for _, r := range []rune("[ x:" + strconv.FormatInt(int64(game.player.position.x), 10) + " y:" + strconv.FormatInt(int64(game.player.position.y), 10) + " ]") {
  40. game.screen.SetContent(x, y-1, r, nil, game.style)
  41. x++
  42. }
  43. }
  44. func (game *Game) drawDebug() {
  45. var x, y int = 40, 24
  46. for _, r := range []rune("[ NumGoRoutine: " + strconv.FormatInt(int64(runtime.NumGoroutine()), 10) + " Bots: " + strconv.FormatInt(int64(len(game.robots)), 10) + " ]") {
  47. game.screen.SetContent(x, y-1, r, nil, game.style)
  48. x++
  49. }
  50. }
  51. func (game *Game) drawScore() {
  52. var x, y int = 5, 24
  53. for _, r := range []rune("[ Score: " + strconv.FormatInt(int64(game.player.score), 10) + " Level: " + strconv.FormatInt(int64(game.level), 10) + " ]") {
  54. game.screen.SetContent(x, y-1, r, nil, game.style)
  55. x++
  56. }
  57. }