send the client max points for the game

This commit is contained in:
Stephen McQuay 2014-01-22 22:14:22 -08:00
parent a57903d81c
commit d3070ad501
2 changed files with 16 additions and 10 deletions

13
game.go
View File

@ -357,3 +357,16 @@ func (g *game) sendGameOver(eg *GameOver) {
s.send <- eg s.send <- eg
} }
} }
// returns a GameParam object popuplated by info from the game. This is
// used during client/server initial negociation.
func (g *game) gameParam() *GameParam {
return &GameParam{
BoardSize: BoardSize{
Width: g.width,
Height: g.height,
},
MaxPoints: g.maxPoints,
Type: "gameparam",
}
}

View File

@ -71,20 +71,13 @@ type BoardSize struct {
} }
type GameParam struct { type GameParam struct {
// TODO: should have information about max points in here
BoardSize BoardSize `json:"boardsize"` BoardSize BoardSize `json:"boardsize"`
MaxPoints int `json:"max_points"`
Type string `json:"type"` Type string `json:"type"`
} }
// > [OK | FULL | NOT AUTH], board size, game params // > [OK | FULL | NOT AUTH], board size, game params
func NewGameParam(w, h float32) *GameParam {
return &GameParam{
BoardSize: BoardSize{
Width: w,
Height: h,
},
Type: "gameparam",
}
}
type Handshake struct { type Handshake struct {
ID string `json:"id"` ID string `json:"id"`
@ -197,7 +190,7 @@ func addPlayer(ws *websocket.Conn) {
return return
} }
gameParam := NewGameParam(game.width, game.height) gameParam := game.gameParam()
err = websocket.JSON.Send(ws, gameParam) err = websocket.JSON.Send(ws, gameParam)
if err != nil { if err != nil {
log.Printf("%s %s game param parse error", gid.Id, player_id) log.Printf("%s %s game param parse error", gid.Id, player_id)