send the client max points for the game
This commit is contained in:
parent
a57903d81c
commit
d3070ad501
13
game.go
13
game.go
@ -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",
|
||||
}
|
||||
}
|
||||
|
13
protocol.go
13
protocol.go
@ -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…
Reference in New Issue
Block a user