Update to new protocol (Update)

This commit is contained in:
sm
2014-05-11 23:13:00 -07:00
parent d3e7a247c8
commit 14297191ed
2 changed files with 30 additions and 23 deletions
+4 -6
View File
@@ -31,7 +31,7 @@ type Client struct {
Player Player
Game server.GameParam
boardstate server.Boardstate
boardstate *server.Boardstate
enc encoder
dec decoder
ws *websocket.Conn
@@ -164,16 +164,14 @@ func (c *Client) Negociate(clientType string) (err error) {
func (c *Client) Play() error {
log.Printf("%s: starting loop", c.Name)
bs := &server.Boardstate{}
var err error
for {
err = c.dec.Decode(&c.boardstate)
err = c.dec.Decode(bs)
if err != nil {
return errors.New(fmt.Sprintf("%s: Connection likely lost: %s", c.Name, err))
}
c.Player.Recv(&c.boardstate)
instruction := c.Player.Instruction()
err = c.enc.Encode(instruction)
err = c.enc.Encode(c.Player.Update(bs))
if err != nil {
return err
}