client/cmd/botspectate/main.go

52 lines
928 B
Go
Raw Normal View History

package main
import (
"flag"
2015-08-31 21:55:18 -07:00
"fmt"
"math/rand"
2015-08-31 21:55:18 -07:00
"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())
2016-07-13 19:49:59 -07:00
var gameID string
flag.Parse()
if flag.NArg() < 1 {
2016-07-13 19:49:59 -07:00
gameID = "debug"
} else {
2016-07-13 19:49:59 -07:00
gameID = flag.Arg(0)
}
c := &client.Client{
2016-07-13 19:49:59 -07:00
Server: *addr,
Name: "bspect",
GameId: gameID,
ForceJSON: *forceJSON,
}
var err error
err = c.Negotiate("spectator", c.Player)
if err != nil {
2016-07-13 11:31:28 -07:00
fmt.Fprintf(os.Stderr, "%s: failed to negotiate: %s\n", c.Name, err)
2015-08-31 21:55:18 -07:00
os.Exit(1)
}
2016-07-13 19:49:59 -07:00
ui := client.NewSpectator(c.Width, c.Height)
c.Player = ui
2014-05-04 00:33:46 -07:00
go func() {
if err := c.Play(); err != nil {
2016-07-13 19:49:59 -07:00
close(ui.Die)
2014-05-04 00:33:46 -07:00
}
}()
2016-07-13 19:49:59 -07:00
if err := ui.Spectate(); err != nil {
fmt.Fprintf(os.Stderr, "problem during visualization: %+v\n", err)
os.Exit(1)
}
}