2014-04-26 14:50:58 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2015-08-31 21:55:18 -07:00
|
|
|
"fmt"
|
2014-04-26 14:50:58 -07:00
|
|
|
"math/rand"
|
2015-08-31 21:55:18 -07:00
|
|
|
"os"
|
2014-04-26 14:50:58 -07:00
|
|
|
"time"
|
|
|
|
|
2015-04-30 23:14:17 -07:00
|
|
|
"hackerbots.us/client"
|
2014-04-26 14:50:58 -07:00
|
|
|
)
|
|
|
|
|
2016-07-13 18:40:41 -07:00
|
|
|
var addr = flag.String("addr", "ws://localhost:8666", "server hostname")
|
2014-04-26 14:50:58 -07:00
|
|
|
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
|
2014-04-26 14:50:58 -07:00
|
|
|
flag.Parse()
|
|
|
|
if flag.NArg() < 1 {
|
2016-07-13 19:49:59 -07:00
|
|
|
gameID = "debug"
|
2014-04-26 14:50:58 -07:00
|
|
|
} else {
|
2016-07-13 19:49:59 -07:00
|
|
|
gameID = flag.Arg(0)
|
2014-04-26 14:50:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
c := &client.Client{
|
2016-07-13 19:49:59 -07:00
|
|
|
Server: *addr,
|
|
|
|
Name: "bspect",
|
|
|
|
GameId: gameID,
|
|
|
|
ForceJSON: *forceJSON,
|
2014-04-26 14:50:58 -07:00
|
|
|
}
|
|
|
|
var err error
|
2016-07-13 15:04:48 -07:00
|
|
|
err = c.Negotiate("spectator", c.Player)
|
2014-04-26 14:50:58 -07:00
|
|
|
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)
|
2014-04-26 14:50:58 -07:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
2014-04-26 14:50:58 -07:00
|
|
|
}
|