Browse Source

update imports for golang.org/x/

master
Stephen McQuay 8 years ago
parent
commit
5b6938b927
  1. 3
      main.go
  2. 31
      player.go

3
main.go

@ -1,11 +1,12 @@
package main
import (
"code.google.com/p/go.net/websocket"
"flag"
"fmt"
"log"
"net/http"
"golang.org/x/net/websocket"
)
var addr = flag.String("addr", ":8666", "http service address")

31
player.go

@ -1,11 +1,12 @@
package main
import (
"code.google.com/p/go.net/websocket"
"encoding/json"
"fmt"
"log"
"math"
"math"
"golang.org/x/net/websocket"
)
type Position struct {
@ -20,14 +21,14 @@ type player struct {
}
func (p *player) validMove(next Position) (r bool) {
r = true
if math.Abs(float64(p.Position.X - next.X)) > 1 {
r = false
}
if math.Abs(float64(p.Position.Y - next.Y)) > 1 {
r = false
}
return
r = true
if math.Abs(float64(p.Position.X-next.X)) > 1 {
r = false
}
if math.Abs(float64(p.Position.Y-next.Y)) > 1 {
r = false
}
return
}
func (p *player) sender() {
@ -48,15 +49,15 @@ func (p *player) recv() {
break
}
// XXX: the danger!
var pos Position
var pos Position
err = json.Unmarshal([]byte(msg), &pos)
if err != nil {
break
}
if !p.validMove(pos) {
break
}
p.Position = pos
if !p.validMove(pos) {
break
}
p.Position = pos
g.broadcast <- p
}
p.ws.Close()

Loading…
Cancel
Save