Browse Source

send the client max points for the game

master
Stephen McQuay 6 years ago
parent
commit
d3070ad501
2 changed files with 16 additions and 10 deletions
  1. +13
    -0
      game.go
  2. +3
    -10
      protocol.go

+ 13
- 0
game.go View File

@ -357,3 +357,16 @@ func (g *game) sendGameOver(eg *GameOver) {
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",
}
}

+ 3
- 10
protocol.go View File

@ -71,20 +71,13 @@ type BoardSize struct {
}
type GameParam struct {
// TODO: should have information about max points in here
BoardSize BoardSize `json:"boardsize"`
MaxPoints int `json:"max_points"`
Type string `json:"type"`
}
// > [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 {
ID string `json:"id"`
@ -197,7 +190,7 @@ func addPlayer(ws *websocket.Conn) {
return
}
gameParam := NewGameParam(game.width, game.height)
gameParam := game.gameParam()
err = websocket.JSON.Send(ws, gameParam)
if err != nil {
log.Printf("%s %s game param parse error", gid.Id, player_id)

Loading…
Cancel
Save