public void AddPlayerScores(PlayerProfile profile, PlayerScoreData scoreData) { if (!PlayerProfiles.Contains(profile)) { PlayerProfiles.Add(profile); } playerScoreMap[profile] = scoreData; }
private void Awake() { if (Instance != null) { Destroy(gameObject); return; } Instance = this; }
public PlayerManager(GameObject prefab, string name, int id, Material mat) { _prefab = prefab; _name = name; _id = id; _mat = mat; _state = new StateBools(); _state.Reset(); _stats = new PlayerStatsData(); _score = new PlayerScoreData(); Credits = 0; }
public void UpdateData(PlayerScoreData data, bool delay = false) { this.data = data; if (!delay) { PlayAnim(); } else { Invoke("PlayAnim", 1); } }
public WaitingPlayerResult GetWaitingPlayersList(string excludedEmail) { logger.Info("GetWaitingPlayr "); WaitingPlayerResult result = new WaitingPlayerResult(); foreach (string email in waitingPlayers) { if (email == excludedEmail) { continue; } WaitingPlayer waitingPlayer = new WaitingPlayer(); PlayerScoreData playerData = matixData.GetWaitingPlayerData(email); waitingPlayer.NickName = userEmailToNickname[email]; waitingPlayer.TotalGames = playerData.TotalNumberOfGames; waitingPlayer.TotalScore = playerData.TotalScore; waitingPlayer.NumberOfWinnings = playerData.NumberOfWinnings; result.WaitingPlayerslist.Add(waitingPlayer); } WaitingPlayer waitingPlayer1 = new WaitingPlayer(); waitingPlayer1.NickName = "Player1"; waitingPlayer1.TotalGames = 15; waitingPlayer1.TotalScore = 85; waitingPlayer1.NumberOfWinnings = 7; result.WaitingPlayerslist.Add(waitingPlayer1); waitingPlayer1 = new WaitingPlayer(); waitingPlayer1.NickName = "Player2"; waitingPlayer1.TotalGames = 150; waitingPlayer1.TotalScore = -6585; waitingPlayer1.NumberOfWinnings = 87; result.WaitingPlayerslist.Add(waitingPlayer1); waitingPlayer1 = new WaitingPlayer(); waitingPlayer1.NickName = "Player__3"; waitingPlayer1.TotalGames = 25; waitingPlayer1.TotalScore = 45; waitingPlayer1.NumberOfWinnings = 17; result.WaitingPlayerslist.Add(waitingPlayer1); result.Status = OperationStatusnEnum.Success; return(result); }
public void Score(int score) { if (score > highscores [highscores.Count - 1].score) { highscoreCanvas.enabled = false; enterNameCanvas.enabled = true; tmp = new PlayerScoreData("", score); } else { highscoreCanvas.enabled = true; enterNameCanvas.enabled = false; Invoke("MainMenu", 5f); } }
public PlayerScoreData LoadPlayerScoreData() { var playerScoreData = new PlayerScoreData(); if (SaveSystem.SaveFileExists(SaveFileName)) { playerScoreData = SaveSystem.Load <PlayerScoreData>(SaveFileName); } else { while (playerScoreData.list.Count < 10) { playerScoreData.list.Add(new PlayerScore(0, playerName)); } SaveSystem.Save(SaveFileName, playerScoreData); } return(playerScoreData); }
public void AddScore(PlayerScoreData playerScoreData) { highscoresList.AddToHighscoreList(playerScoreData); //leaderboard.PopulateLeaderboard(highscoresList.HIGHSCORES); OnGameRestart(); }
public GameOverScreen() : base("data/GameOver Screen.png") { _buttonPressed = true; _scoreTitle = new HudTextBoard("Score Board", 0, 0, 500, 500, FONT_SIZE, CenterMode.Center, CenterMode.Center); AddChild(_scoreTitle); _scoreTitle.SetClearColor(Color.FromArgb(0, 1, 1, 1)); ((IHasColor)_scoreTitle).MainColor = GlobalVars.DarkBlue; _scoreTitle.EasyDraw.TextFont(FONT_PATH, FONT_SIZE); _scoreTitle.SetText("Score Board"); _scoreTitle.x = SCOREBOARD_X + 60; _scoreTitle.y = 100; _scoreTitle.EasyDraw.TextFont(FONT_PATH, FONT_SIZE); var playerScoreData = new PlayerScoreData() { name = "you", score = MyGame.ThisInstance.TotalScore }; var scorePointsList = new List <PlayerScoreData>(MyGame.ThisInstance.ScoreBoardList) { playerScoreData }; scorePointsList = scorePointsList.OrderByDescending(ps => ps.score).ToList(); int pad = 0; if (scorePointsList.Count > 0) { pad = scorePointsList[0].score.ToString().Length; } var first10Scores = scorePointsList.Take(10).ToList(); _scoreBoardTexts = new List <HudTextBoard>(); for (int i = 0; i < first10Scores.Count; i++) { var scoreData = scorePointsList[i]; var format = "{0,2}\t{1}\t{2," + pad + "}"; var text = string.Format(format, i + 1, scoreData.name.ToUpper().Substring(0, 3), scoreData.score); //$"{scoreData.name.ToUpper().Substring(0, 3)} {$"{scoreData.score:10}"}"; var hudScoreText = new HudTextBoard(text, 0, 0, 1000, 200, FONT_SIZE, CenterMode.Min, CenterMode.Min); AddChild(hudScoreText); hudScoreText.SetClearColor(Color.FromArgb(0, 1, 1, 1)); ((IHasColor)hudScoreText).MainColor = (scoreData.name == "you") ? GlobalVars.DimGreen : GlobalVars.DarkBlue; hudScoreText.EasyDraw.TextFont(FONT_PATH, FONT_SIZE); hudScoreText.SetText(text); if (scoreData.name == "you") { hudScoreText.EasyDraw.SetOrigin(hudScoreText.EasyDraw.width * 0.5f, hudScoreText.EasyDraw.height * 0.5f); hudScoreText.x = SCOREBOARD_X + hudScoreText.EasyDraw.width * 0.5f; hudScoreText.y = 210 + i * 40 + hudScoreText.EasyDraw.height * 0.5f; //Anim score float mScale = hudScoreText.EasyDraw.scale; SpriteTweener.TweenScalePingPong(hudScoreText.EasyDraw, mScale, mScale * 1.02f, 200); } else { hudScoreText.x = SCOREBOARD_X; hudScoreText.y = 200 + i * 40; } } //Get player position, if greater than 10, put it at the end var playerPos = scorePointsList.Select(ps => ps.name).ToList().IndexOf("you"); if (playerPos > 9) { var format = "{0,2}\t{1}\t{2," + pad + "}"; var text = string.Format(format, playerPos + 1, playerScoreData.name.ToUpper().Substring(0, 3), playerScoreData.score); var hudScoreText = new HudTextBoard(text, 0, 0, 1000, 200, FONT_SIZE, CenterMode.Min, CenterMode.Min); AddChild(hudScoreText); hudScoreText.SetClearColor(Color.FromArgb(0, 1, 1, 1)); ((IHasColor)hudScoreText).MainColor = GlobalVars.DimGreen; hudScoreText.EasyDraw.TextFont(FONT_PATH, FONT_SIZE); hudScoreText.SetText(text); hudScoreText.EasyDraw.SetOrigin(hudScoreText.EasyDraw.width * 0.5f, hudScoreText.EasyDraw.height * 0.5f); hudScoreText.x = SCOREBOARD_X + hudScoreText.EasyDraw.width * 0.5f; hudScoreText.y = 200 + 30 + first10Scores.Count * 40 + hudScoreText.EasyDraw.height * 0.5f; //Anim score float mScale = hudScoreText.EasyDraw.scale; SpriteTweener.TweenScalePingPong(hudScoreText.EasyDraw, mScale, mScale * 1.02f, 200); } MyGame.ThisInstance.SaveScoreBoard(); CoroutineManager.StartCoroutine(WaitSomeTimeToEnableInput(), this); }
/// <summary> /// A coroutine that adds a new PlayerScoreData to the playerScoreDataList by running the coroutine. /// </summary> /// <returns></returns> private IEnumerator AddNewScoreCoroutine(string name = "", int score = -1) { isAddNewScoreCoroutineRunning = true; // Retrieve user name and score value string newName = name; int newScore = score; // If using testing features, use input fields to gain values from test scene. Otherwise, don't. if (useTestFeatures) { // Retrieve user name newName = userNameInput.text; if (debugComponent) { Debug.Log("newName: " + newName); } // Convert score text to int newScore = int.Parse(scoreInput.text); if (debugComponent) { Debug.Log("newScore: " + newScore); } } else { if (string.IsNullOrEmpty(newName) || newName == "") { Debug.LogError("The newName is empty, null, or has no characters. Only strings with at least one character are allowed for names."); yield break; } if (newScore < 0) { Debug.LogError("The newScore added contains values less than 0. Only positive integers are allowed for score values."); yield break; } } // Make new PlayerScoreData object to add to the list PlayerScoreData playerScoreData = new PlayerScoreData(); playerScoreData.userName = newName; playerScoreData.score = newScore; if (debugComponent) { Debug.Log("playerScoreData.userName: "******"playerScoreData.score: " + playerScoreData.score); } // Be warry of data races at this point if another user is doing the same thing simultanously... // Store new value in list playerScoreDataList.Add(playerScoreData); // Sort greatest to least playerScoreDataList.Sort((a, b) => b.score.CompareTo(a.score)); // Remove least value if list count is over maxScoresQuantity. if (playerScoreDataList.Count > maxScoresQuantity) { playerScoreDataList.Remove(playerScoreDataList[playerScoreDataList.Count - 1]); } // Make new ScoreData object ScoreData newScoreData = new ScoreData(); newScoreData.playerScoreDataList = playerScoreDataList; // Convert list to JSON string json = JsonUtility.ToJson(newScoreData); if (debugComponent) { Debug.Log("json: " + Environment.NewLine + json); } // Upload JSON to Database if (_database != null) { var sendData = _database.GetReference(path: SCORELISTKEY).SetRawJsonValueAsync(json); yield return(new WaitUntil(() => sendData.IsCompleted)); } else { Debug.LogError("Firebase database instance not found. Please initialize the database in order to upload data."); } isAddNewScoreCoroutineRunning = false; }
void Update() { int index = 0; foreach (PlayerScoreData data in highscores) { places [index].text = data.name; scores[index].text = data.score.ToString(); index = index + 1; } if (Input.GetKeyDown(KeyCode.Space)) { highscoreCanvas.enabled = !highscoreCanvas.enabled; enterNameCanvas.enabled = !enterNameCanvas.enabled; tmp = new PlayerScoreData("tes", 10101); } if (enterNameCanvas.enabled) { if (Input.GetKeyDown(KeyCode.Backspace)) { name = name.Substring(0, name.Length - 1); } else if (Input.GetKeyDown(KeyCode.Return)) { if (name.Length == 3) { highscoreCanvas.enabled = !highscoreCanvas.enabled; enterNameCanvas.enabled = !enterNameCanvas.enabled; tmp.name = name; name = ""; highscores.Add(tmp); highscores.Sort(); highscores.Reverse(); highscores.RemoveAt(highscores.Count - 1); Invoke("MainMenu", 5f); } } else { if (name.Length < 3) { if (Input.anyKey && !Input.GetKeyDown(KeyCode.Space)) { name = name + Input.inputString; } } } int charIndex = 0; foreach (char c in name) { letters[charIndex].text = c.ToString(); charIndex = charIndex + 1; } for (int i = charIndex; i < 3; i++) { letters[i].text = "_"; } } }
public void AddToHighscoreList(PlayerScoreData playerScoreData) { Highscores.Add(playerScoreData); Highscores.Sort(); Save(); }