// google app engine 的入口函数 func init() { newGame := game.NewGame() go game.CheckLivePlayers() game.GetGameManagerInstance().AddGame(newGame) http.HandleFunc("/joinGame", controller.Join) //设置访问的路由 http.HandleFunc("/getPlayer", controller.GetPlayer) http.HandleFunc("/talk2Others", controller.Talk2Others) http.HandleFunc("/getNewMsg", controller.GetNewMsg) }
func main() { svc := NewServiceContext() comm.AvatarFunc = sf.MakeAvatar go comm.NewCommService(svc, "0.0.0.0:9190").Run(svc.Comm) go pubsub.NewPubSub(svc).Run(svc.PubSub) go sf.NewWorld(svc).Run(svc.World) game.InitFunc = initGameSvc game := game.NewGame(svc) game.Run(svc.Game) }
// Starts the server with a user specificied ServiceContext func startServerWithCtx(t *testing.T, ctx ServiceContext) (svc *CommService, cs chan Msg) { // Start new service on port 9190 svc = NewCommService(ctx, ":9190") go util.Drain(ctx.Game) // For service ready msg cs = ctx.Comm go svc.Run(cs) // Start game and pubsub so observers don't lock up go game.NewGame(ctx).Run(ctx.Game) go pubsub.NewPubSub(ctx).Run(ctx.PubSub) // Give time for the service to start listening time.Sleep(1e8) // 100 ms return svc, cs }
func main() { fmt.Println("start") game := game.NewGame() go game.Start() fs := http.FileServer(http.Dir("static")) http.Handle("/static/", http.StripPrefix("/static/", fs)) http.HandleFunc("/", serveHome) http.HandleFunc("/ws", ws.HandlerFactory(game)) err := http.ListenAndServe(":7102", nil) if err != nil { panic(err) } fmt.Println("stop") }