Exemplo n.º 1
0
func Join(resp http.ResponseWriter, req *http.Request) {
	game.CurrentContext = appengine.NewContext(req)
	game.Infof("joinGame url: %v", req.URL)

	userName := req.FormValue("userName")
	gameId := req.FormValue("gameId")
	game.Infof("game username: %s, id: %s", userName, gameId)

	// add to manager
	allPlayers := joinGame(userName, gameId)

	// 返回所有游戏里面的成员
	jsonPlayers, _ := json.Marshal(allPlayers)
	fmt.Fprintf(resp, string(jsonPlayers))

	//http.Error(resp, "Couldn't create Channel", http.StatusInternalServerError)
}
Exemplo n.º 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")
	}
}
Exemplo n.º 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}
	}
}