got simple testing server working
This commit is contained in:
parent
ccd5dc3961
commit
880d73b54e
14
game.go
14
game.go
@ -19,6 +19,20 @@ type game struct {
|
||||
sunregister chan *Spectator
|
||||
}
|
||||
|
||||
func NewGame() *game {
|
||||
return &game{
|
||||
register: make(chan *player),
|
||||
unregister: make(chan *player),
|
||||
projectiles: make(map[*projectile]bool),
|
||||
splosions: make(map[*splosion]bool),
|
||||
players: make(map[*player]bool),
|
||||
turn: 0,
|
||||
spectators: make(map[*Spectator]bool),
|
||||
sregister: make(chan *Spectator),
|
||||
sunregister: make(chan *Spectator),
|
||||
}
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ID string `json:"id"`
|
||||
Stats stats `json:"stats"`
|
||||
|
13
main.go
13
main.go
@ -19,17 +19,7 @@ var width = flag.Float64("width", 800, "width of field")
|
||||
var height = flag.Float64("height", 550, "height of field")
|
||||
|
||||
var delta float64
|
||||
var g = game{
|
||||
register: make(chan *player),
|
||||
unregister: make(chan *player),
|
||||
projectiles: make(map[*projectile]bool),
|
||||
splosions: make(map[*splosion]bool),
|
||||
players: make(map[*player]bool),
|
||||
turn: 0,
|
||||
spectators: make(map[*Spectator]bool),
|
||||
sregister: make(chan *Spectator),
|
||||
sunregister: make(chan *Spectator),
|
||||
}
|
||||
var g *game
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
@ -39,6 +29,7 @@ func main() {
|
||||
|
||||
http.Handle("/ws/", websocket.Handler(addPlayer))
|
||||
|
||||
g = NewGame()
|
||||
go g.run()
|
||||
|
||||
err := http.ListenAndServe(*addr, nil)
|
||||
|
@ -1,7 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.net/websocket"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -43,3 +46,24 @@ func TestClientIDParse(t *testing.T) {
|
||||
t.Errorf("fail to parse: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProtocol(t *testing.T) {
|
||||
http.Handle("/ws/", websocket.Handler(addPlayer))
|
||||
|
||||
g = NewGame()
|
||||
go g.run()
|
||||
|
||||
go http.ListenAndServe(*addr, nil)
|
||||
|
||||
origin := "http://localhost/"
|
||||
url := "ws://localhost:8666/ws/"
|
||||
ws, err := websocket.Dial(url, "", origin)
|
||||
if err != nil {
|
||||
t.Errorf("fail: %v", err)
|
||||
}
|
||||
conf, err := Negociate(ws, "robot0", 800, 400)
|
||||
if err != nil {
|
||||
t.Errorf("fail: %v", err)
|
||||
}
|
||||
log.Printf("%+v", conf)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user