示例#1
0
// 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)
}
示例#2
0
func GetNewMsg(resp http.ResponseWriter, req *http.Request) {
	game.CurrentContext = appengine.NewContext(req)
	userName := req.FormValue("userName")
	gameId := req.FormValue("gameId")

	iGameId, _ := strconv.Atoi(gameId)
	gameIn := game.GetGameManagerInstance().GetGame(iGameId)
	player := gameIn.GetPlayer(userName)
	player.Live()
	if player != nil {
		player.SendNewMsg2Client(resp, appengine.NewContext(req))
	} else {
		game.Infof("%s not found", userName)
		fmt.Fprintf(resp, "noMsg")
	}
}
示例#3
0
func joinGame(name string, gameId string) []*game.Player {
	player := game.NewPlayer(name, 0, 0)
	gameManager := game.GetGameManagerInstance()
	iGameId, _ := strconv.Atoi(gameId)
	game.GetPlayerManagerInstance().AddPlayer(player)

	gameIn := gameManager.GetGame(iGameId)

	if gameIn != nil {
		gameIn.Join(player)
		return gameIn.GetAllPlayer()
	} else {
		game.Infof("joinGame not found game: %d", name, gameManager.GetGameCount())
		// 返回自己
		return []*game.Player{player}
	}
}