Exemplo n.º 1
0
func TestGetAllPlayer(t *testing.T) {
	playerManager := game.GetPlayerManagerInstance()
	playerManager.RemoveAllPlayer()

	player := game.NewPlayer("na1", 0, 0)
	playerManager.AddPlayer(player)

	jsonContent := getAllPlayer()
	testUtil.AssertEqual("[{\"Name\":\"na1\",\"PosX\":0,\"PosY\":0}]", jsonContent, "TestGetJson", t)

	player2 := game.NewPlayer("na2", 2, 2)
	playerManager.AddPlayer(player2)

	jsonContent = getAllPlayer()
	testUtil.AssertEqual("[{\"Name\":\"na1\",\"PosX\":0,\"PosY\":0},{\"Name\":\"na2\",\"PosX\":2,\"PosY\":2}]", jsonContent, "TestGetJson", t)

}
Exemplo n.º 2
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}
	}
}