client/cmd/botspectate/main.go

52 lines
928 B
Go

package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
"hackerbots.us/client"
)
var addr = flag.String("addr", "ws://localhost:8666", "server hostname")
var forceJSON = flag.Bool("json", false, "force json encoding")
func main() {
rand.Seed(time.Now().UnixNano())
var gameID string
flag.Parse()
if flag.NArg() < 1 {
gameID = "debug"
} else {
gameID = flag.Arg(0)
}
c := &client.Client{
Server: *addr,
Name: "bspect",
GameId: gameID,
ForceJSON: *forceJSON,
}
var err error
err = c.Negotiate("spectator", c.Player)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: failed to negotiate: %s\n", c.Name, err)
os.Exit(1)
}
ui := client.NewSpectator(c.Width, c.Height)
c.Player = ui
go func() {
if err := c.Play(); err != nil {
close(ui.Die)
}
}()
if err := ui.Spectate(); err != nil {
fmt.Fprintf(os.Stderr, "problem during visualization: %+v\n", err)
os.Exit(1)
}
}