Exemplo n.º 1
0
func GetPlayerById(render render.Render, request *http.Request, params martini.Params) {
	var id int
	_, err := fmt.Sscanf(params["id"], "%d", &id)
	if err != nil {
		log.Error(err.Error())
	}

	player, err := database.GetPlayer(id)
	if err != nil {
		log.Error(err.Error())
	}

	stats, err := database.GetPlayerAllTimeStats(id)
	if err != nil {
		log.Error(err.Error())
	}

	// rank, err := database.GetPlayerRank(id)
	// if err != nil {
	// 	 log.Error(err.Error())
	// }

	playerProfile := PlayerProfile{
		Player: *player,
		Stats:  *stats,
		//Rank: *rank,
	}

	render.HTML(http.StatusOK, "player", playerProfile)
}
Exemplo n.º 2
0
func CreateGame(render render.Render, writer http.ResponseWriter, request *http.Request, gameData GameData) {
	///////////////////////////////////////////////////////////////////////////////
	// Get Stage Info
	stage, err := database.GetStageByName(gameData.Stage)
	if err != nil {
		log.Error(err.Error())
	}

	///////////////////////////////////////////////////////////////////////////////
	//Get Player Count
	var playerCount int
	_, err = fmt.Sscanf(gameData.PlayerCount, "%d", &playerCount)
	if err != nil {
		log.Error(err.Error())
	}

	///////////////////////////////////////////////////////////////////////////////
	//Get Player Stats

	playerStats := models.PlayerStats{}

	/**** Player One ****/
	if playerCount >= 1 {
		// Player
		var playerOneId int
		_, err = fmt.Sscanf(gameData.PlayerOneId, "%d", &playerOneId)
		if err != nil {
			log.Error(err.Error())
		}
		player1, err := database.GetPlayer(playerOneId)
		if err != nil {
			log.Error(err.Error())
		}

		// Character
		var characterOneId int
		_, err = fmt.Sscanf(gameData.CharacterOneId, "%d", &characterOneId)
		if err != nil {
			log.Error(err.Error())
		}
		character1, err := database.GetCharacter(characterOneId)
		if err != nil {
			log.Error(err.Error())
		}

		// IsRandom
		var isP1Random bool
		if gameData.IsP1Random == "1" {
			isP1Random = true
		} else {
			isP1Random = false
		}

		// Rank
		var rankOne int
		_, err = fmt.Sscanf(gameData.RankOne, "%d", &rankOne)
		if err != nil {
			log.Error(err.Error())
		}

		// Kills
		var killsOne int
		_, err = fmt.Sscanf(gameData.KillsOne, "%d", &killsOne)
		if err != nil {
			log.Error(err.Error())
		}

		// Deaths
		var deathsOne int
		_, err = fmt.Sscanf(gameData.DeathsOne, "%d", &deathsOne)
		if err != nil {
			log.Error(err.Error())
		}

		// SelfDestructs
		var sdOne int
		_, err = fmt.Sscanf(gameData.SDOne, "%d", &sdOne)
		if err != nil {
			log.Error(err.Error())
		}

		playerStats = append(playerStats,
			&models.PlayerStat{
				Player:        player1,
				Character:     character1,
				IsRandom:      isP1Random,
				Rank:          rankOne,
				Number:        1,
				Kills:         killsOne,
				Deaths:        deathsOne,
				SelfDestructs: sdOne,
			})
	}

	/**** Player Two ****/
	if playerCount >= 2 {
		// Player
		var playerTwoId int
		_, err = fmt.Sscanf(gameData.PlayerTwoId, "%d", &playerTwoId)
		if err != nil {
			log.Error(err.Error())
		}
		player2, err := database.GetPlayer(playerTwoId)
		if err != nil {
			log.Error(err.Error())
		}

		// Character
		var characterTwoId int
		_, err = fmt.Sscanf(gameData.CharacterTwoId, "%d", &characterTwoId)
		if err != nil {
			log.Error(err.Error())
		}
		character2, err := database.GetCharacter(characterTwoId)
		if err != nil {
			log.Error(err.Error())
		}

		// IsRandom
		var isP2Random bool
		if gameData.IsP2Random == "1" {
			isP2Random = true
		} else {
			isP2Random = false
		}

		// Rank
		var rankTwo int
		_, err = fmt.Sscanf(gameData.RankTwo, "%d", &rankTwo)
		if err != nil {
			log.Error(err.Error())
		}

		// Kills
		var killsTwo int
		_, err = fmt.Sscanf(gameData.KillsTwo, "%d", &killsTwo)
		if err != nil {
			log.Error(err.Error())
		}

		// Deaths
		var deathsTwo int
		_, err = fmt.Sscanf(gameData.DeathsTwo, "%d", &deathsTwo)
		if err != nil {
			log.Error(err.Error())
		}

		// SelfDestructs
		var sdTwo int
		_, err = fmt.Sscanf(gameData.SDTwo, "%d", &sdTwo)
		if err != nil {
			log.Error(err.Error())
		}

		playerStats = append(playerStats,
			&models.PlayerStat{
				Player:        player2,
				Character:     character2,
				IsRandom:      isP2Random,
				Rank:          rankTwo,
				Number:        2,
				Kills:         killsTwo,
				Deaths:        deathsTwo,
				SelfDestructs: sdTwo,
			})
	}

	/**** Player Three ****/
	if playerCount >= 3 {
		// Player
		var playerThreeId int
		_, err = fmt.Sscanf(gameData.PlayerThreeId, "%d", &playerThreeId)
		if err != nil {
			log.Error(err.Error())
		}
		player3, err := database.GetPlayer(playerThreeId)
		if err != nil {
			log.Error(err.Error())
		}

		// Character
		var characterThreeId int
		_, err = fmt.Sscanf(gameData.CharacterThreeId, "%d", &characterThreeId)
		if err != nil {
			log.Error(err.Error())
		}
		character3, err := database.GetCharacter(characterThreeId)
		if err != nil {
			log.Error(err.Error())
		}

		// IsRandom
		var isP3Random bool
		if gameData.IsP3Random == "1" {
			isP3Random = true
		} else {
			isP3Random = false
		}

		// Rank
		var rankThree int
		_, err = fmt.Sscanf(gameData.RankThree, "%d", &rankThree)
		if err != nil {
			log.Error(err.Error())
		}

		// Kills
		var killsThree int
		_, err = fmt.Sscanf(gameData.KillsThree, "%d", &killsThree)
		if err != nil {
			log.Error(err.Error())
		}

		// Deaths
		var deathsThree int
		_, err = fmt.Sscanf(gameData.DeathsThree, "%d", &deathsThree)
		if err != nil {
			log.Error(err.Error())
		}

		// SelfDestructs
		var sdThree int
		_, err = fmt.Sscanf(gameData.SDThree, "%d", &sdThree)
		if err != nil {
			log.Error(err.Error())
		}

		playerStats = append(playerStats,
			&models.PlayerStat{
				Player:        player3,
				Character:     character3,
				IsRandom:      isP3Random,
				Rank:          rankThree,
				Number:        3,
				Kills:         killsThree,
				Deaths:        deathsThree,
				SelfDestructs: sdThree,
			})
	}

	/**** Player Four ****/

	if playerCount == 4 {
		// Player
		var playerFourId int
		_, err = fmt.Sscanf(gameData.PlayerFourId, "%d", &playerFourId)
		if err != nil {
			log.Error(err.Error())
		}
		player4, err := database.GetPlayer(playerFourId)
		if err != nil {
			log.Error(err.Error())
		}

		// Character
		var characterFourId int
		_, err = fmt.Sscanf(gameData.CharacterFourId, "%d", &characterFourId)
		if err != nil {
			log.Error(err.Error())
		}
		character4, err := database.GetCharacter(characterFourId)
		if err != nil {
			log.Error(err.Error())
		}

		// IsRandom
		var isP4Random bool
		if gameData.IsP4Random == "1" {
			isP4Random = true
		} else {
			isP4Random = false
		}

		// Rank
		var rankFour int
		_, err = fmt.Sscanf(gameData.RankFour, "%d", &rankFour)
		if err != nil {
			log.Error(err.Error())
		}

		// Kills
		var killsFour int
		_, err = fmt.Sscanf(gameData.KillsFour, "%d", &killsFour)
		if err != nil {
			log.Error(err.Error())
		}

		// Deaths
		var deathsFour int
		_, err = fmt.Sscanf(gameData.DeathsFour, "%d", &deathsFour)
		if err != nil {
			log.Error(err.Error())
		}

		// SelfDestructs
		var sdFour int
		_, err = fmt.Sscanf(gameData.SDFour, "%d", &sdFour)
		if err != nil {
			log.Error(err.Error())
		}

		playerStats = append(playerStats,
			&models.PlayerStat{
				Player:        player4,
				Character:     character4,
				IsRandom:      isP4Random,
				Rank:          rankFour,
				Number:        4,
				Kills:         killsFour,
				Deaths:        deathsFour,
				SelfDestructs: sdFour,
			})
	}

	gameModel := models.Game{
		Stage:       stage,
		PlayerCount: playerCount,
		Time:        time.Now(),
		PlayerStats: playerStats,
	}

	_, err = database.CreateGame(&gameModel)
	if err != nil {
		log.Error(err.Error())
	}

	render.Redirect("/games")
}