added gameover packet

This commit is contained in:
sm
2013-11-13 22:24:54 -08:00
parent aabda1cc90
commit 84ed6c9c32
4 changed files with 97 additions and 73 deletions
+38 -2
View File
@@ -101,6 +101,42 @@ func NewHandshake(id string, success bool) *Handshake {
}
}
type Message interface {
}
type Boardstate struct {
MyRobots []Robot `json:"my_robots"`
OtherRobots []OtherRobot `json:"robots"`
Projectiles []Projectile `json:"projectiles"`
Splosions []Splosion `json:"splosions"`
Obstacles []Obstacle `json:"obj"`
Type string `json:"type"`
Turn int `json:"turn"`
AllBots []BotHealth `json:"all_bots"`
Messages []string `json:"messages"`
}
func NewBoardstate() *Boardstate {
return &Boardstate{
MyRobots: []Robot{},
OtherRobots: []OtherRobot{},
Projectiles: []Projectile{},
Splosions: []Splosion{},
AllBots: []BotHealth{},
Type: "boardstate",
}
}
type GameOver struct {
Type string `json:"type"`
}
func NewGameOver() *GameOver {
return &GameOver{
Type: "gameover",
}
}
type Failure struct {
Reason string `json:"reason"`
Type string `json:"type"`
@@ -199,7 +235,7 @@ func addPlayer(ws *websocket.Conn) {
p := &player{
Robots: []*Robot{},
send: make(chan *Boardstate),
send: make(chan Message),
ws: ws,
}
@@ -226,7 +262,7 @@ func addPlayer(ws *websocket.Conn) {
log.Printf("game %s: player %v has been disconnected from this game\n", gid.Id, p.Robots[0].Id)
case "spectator":
s := &Spectator{
send: make(chan *Boardstate),
send: make(chan Message),
ws: ws,
}
game.sregister <- s