Fixes #4, additional debug

This commit is contained in:
Sacha Ligthert 2023-12-04 01:01:45 +01:00
parent 9aad81f7cd
commit 2e13d93a53
2 changed files with 20 additions and 14 deletions

32
game.go
View File

@ -87,7 +87,7 @@ func (game *Game) gameDirector() {
game.drawScore() game.drawScore()
game.drawPlayer() game.drawPlayer()
//game.drawCoords() //game.drawCoords()
//game.drawDebug() game.drawDebug()
// Draw robots?? // Draw robots??
if len(game.robots) == 0 { if len(game.robots) == 0 {
@ -169,21 +169,27 @@ func quit(game *Game) {
} }
func (game *Game) randPos() Position { func (game *Game) randPos() Position {
var safe bool = false //var safe bool = false
var pos Position var pos Position
for !safe { // for !safe {
x := rand.Intn(80) // x := rand.Intn(80)
y := rand.Intn(24) // y := rand.Intn(24)
if x == 0 || x == 79 || y == 0 || y == 23 { // if x == 0 || x == 79 || y == 0 || y == 23 {
safe = false // safe = false
} else { // } else {
pos.x = x // pos.x = x
pos.y = y // pos.y = y
safe = true // safe = true
} // }
} // }
x := 1 + rand.Intn(77)
y := 1 + rand.Intn(22)
pos.x = x
pos.y = y
return pos return pos
} }

View File

@ -52,7 +52,7 @@ func (game *Game) drawCoords() {
func (game *Game) drawDebug() { func (game *Game) drawDebug() {
var x, y int = 40, 24 var x, y int = 40, 24
for _, r := range []rune("[ NumGoRoutine: " + strconv.FormatInt(int64(runtime.NumGoroutine()), 10) + " ]") { for _, r := range []rune("[ NumGoRoutine: " + strconv.FormatInt(int64(runtime.NumGoroutine()), 10) + " Bots: " + strconv.FormatInt(int64(len(game.robots)), 10) + " ]") {
game.screen.SetContent(x, y-1, r, nil, game.style) game.screen.SetContent(x, y-1, r, nil, game.style)
x++ x++
} }