本文整理汇总了Golang中snake/player.Player类的典型用法代码示例。如果您正苦于以下问题:Golang Player类的具体用法?Golang Player怎么用?Golang Player使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Player类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: create
func create(PlayerOne *player.Player, PlayerTwo *player.Player) {
if PlayerOne.Disconnected || PlayerTwo.Disconnected {
if !PlayerTwo.Disconnected {
Pair(PlayerTwo)
}
if !PlayerOne.Disconnected {
Pair(PlayerOne)
}
return
}
PlayerOne.Position = [][2]int{
[2]int{3, 7},
[2]int{3, 6},
[2]int{3, 5},
[2]int{3, 4},
[2]int{3, 3},
}
PlayerOne.Heading = "down"
PlayerTwo.Position = [][2]int{
[2]int{46, 42},
[2]int{46, 43},
[2]int{46, 44},
[2]int{46, 45},
[2]int{46, 46},
}
PlayerTwo.Heading = "up"
game := &Game{
Width: 50,
Height: 50,
PlayerOne: PlayerOne,
PlayerTwo: PlayerTwo,
Food: [][2]int{},
}
game.run()
}
示例2: pinger
func pinger(p *player.Player, quit chan int) {
p.PingSent = time.Now()
p.ToClient <- map[string]string{"ping": "ping"}
ticker := time.Tick(30e9)
for {
select {
case t := <-ticker:
p.PingSent = t
p.ToClient <- map[string]string{"ping": "ping"}
case <-quit:
return
}
}
}
示例3: receiver
func receiver(ws *websocket.Conn, p *player.Player) chan int {
quit := make(chan int, 0)
go func() {
for {
m := &player.Message{}
err := websocket.JSON.Receive(ws, m)
if err != nil {
break
}
if m.Ping != "" {
fmt.Printf(
"%s %s %s\n",
time.Now().UTC(),
time.Since(p.PingSent),
ws.Request().RemoteAddr,
)
} else {
p.FromClient <- m
}
}
p.Disconnected = true
quit <- 1
}()
return quit
}