adding a listing of all bot id's and health to each payload

This commit is contained in:
Fraser Graham 2013-10-24 06:26:54 -07:00
parent 71f7a262ba
commit cc248dc2fe

13
game.go
View File

@ -12,6 +12,11 @@ import (
const maxPlayer = 128
type BotHealth struct {
RobotId string `json:"robot_id"`
Health int `json:"health"`
}
type Boardstate struct {
Robots []Robot `json:"robots"`
Projectiles []Projectile `json:"projectiles"`
@ -19,12 +24,15 @@ type Boardstate struct {
Reset bool `json:"reset"`
Type string `json:"type"`
Turn int `json:"turn"`
AllBots []BotHealth `json:"all_bots"`
}
func NewBoardstate() *Boardstate {
return &Boardstate{
Robots: []Robot{},
Projectiles: []Projectile{},
Splosions: []Splosion{},
AllBots: []BotHealth{},
Type: "boardstate",
}
}
@ -114,6 +122,10 @@ func (g *game) tick(payload *Boardstate) int {
p.Tick(g)
}
payload.Robots = append(payload.Robots, p.Robot)
payload.AllBots = append(
payload.AllBots,
BotHealth{RobotId: p.Robot.Id, Health: p.Robot.Health})
}
// Update Projectiles
@ -147,6 +159,7 @@ func (g *game) send_update(payload *Boardstate) {
player_payload := NewBoardstate()
player_payload.Projectiles = payload.Projectiles
player_payload.Splosions = payload.Splosions
player_payload.AllBots = payload.AllBots
player_payload.Turn = payload.Turn
player_payload.Reset = payload.Reset
player_payload.Robots = append(player_payload.Robots, p.Robot)