Fix up the tile print now that the radar returns objects

This commit is contained in:
Marc Di Luzio 2020-07-03 17:05:31 +01:00
parent 062f9cfec8
commit c4b0762ebe
2 changed files with 20 additions and 20 deletions

View file

@ -4,13 +4,16 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"os"
"path"
"path/filepath"
"time"
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/bearing"
"github.com/mdiluz/rove/pkg/game"
"github.com/mdiluz/rove/pkg/objects"
"github.com/mdiluz/rove/pkg/rove"
"github.com/mdiluz/rove/pkg/version"
"golang.org/x/net/context"
@ -253,8 +256,24 @@ func InnerMain(command string, args ...string) error {
return err
default:
// Print out the radar
game.PrintTiles(response.Tiles)
num := int(math.Sqrt(float64(len(response.Tiles))))
for j := num - 1; j >= 0; j-- {
for i := 0; i < num; i++ {
t := response.Tiles[i+num*j]
o := response.Objects[i+num*j]
if o != byte(objects.None) {
fmt.Printf("%c", o)
} else if t != byte(atlas.TileNone) {
fmt.Printf("%c", t)
} else {
fmt.Printf(" ")
}
}
fmt.Print("\n")
}
}
case "rover":

View file

@ -4,7 +4,6 @@ import (
"bufio"
"fmt"
"log"
"math"
"math/rand"
"os"
"sync"
@ -425,24 +424,6 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
return
}
// PrintTiles simply prints the input tiles directly for debug
func PrintTiles(tiles []byte) {
num := int(math.Sqrt(float64(len(tiles))))
for j := num - 1; j >= 0; j-- {
for i := 0; i < num; i++ {
t := tiles[i+num*j]
if t != 0 {
fmt.Printf("%c", t)
} else {
fmt.Printf(" ")
}
}
fmt.Print("\n")
}
}
// RLock read locks the world
func (w *World) RLock() {
w.worldMutex.RLock()