Example #1
0
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
}
Example #2
0
// 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)
}