当前位置: 首页>>代码示例>>Golang>>正文


Golang player.Player类代码示例

本文整理汇总了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()
}
开发者ID:benmanns,项目名称:hipstersnake,代码行数:35,代码来源:game.go

示例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
		}
	}
}
开发者ID:benmanns,项目名称:hipstersnake,代码行数:14,代码来源:connection.go

示例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
}
开发者ID:benmanns,项目名称:hipstersnake,代码行数:25,代码来源:connection.go


注:本文中的snake/player.Player类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。