コード例 #1
0
ファイル: ws_handler.go プロジェクト: overmesgit/regame
func HandlerFactory(game *game.Game) func(http.ResponseWriter, *http.Request) {
	res := func(w http.ResponseWriter, r *http.Request) {
		fmt.Println("connection")
		conn, err := upgrader.Upgrade(w, r, nil)
		if err != nil {
			fmt.Println(err)
			return
		}

		player := game.AddPlayer()
		var playerDeadTurn int64 = 0

		for err == nil {
			err = MessageHandler(conn, game, player)
			if playerDeadTurn == 0 && player.GetStructure().GetHealth() <= 0 {
				playerDeadTurn = game.Turn
			}
			if playerDeadTurn != 0 && playerDeadTurn+200 < game.Turn {
				player = game.AddPlayer()
				playerDeadTurn = 0
			}

		}

		game.World.RemoveUnit(player.GetId())
	}
	return res
}
コード例 #2
0
ファイル: main.go プロジェクト: archwyrm/ghack
// Initialize the game with some default data. Eventually this will come from
// data files and those will be loaded elsewhere.
func initGameSvc(g *game.Game, svc ServiceContext) {
	spider := sf.InitSpider(g.GetUid())
	g.AddEntity(spider)
	go spider.Run(svc)
}