render.go 1.9 KB

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