internal void EndGame(EndCondition endCondition)
 {
     if (!GameState.GameHasEnded)
     {
         GameState.GameHasEnded = true;
         ChangePanel(typeof(PanelSelectModule));
         int            gameTime = (int)GameState.GameTime;
         string         text     = endCondition.GetText();
         GameHighScores scores   = HighScore.Load(GameState.Model.Id, GameState.GameHash);
         if (endCondition.GetType() == typeof(EndCondition.Win))
         {
             scores = HighScore.Save(GameState.Model.Id, GameState.GameHash, gameTime, 10);
             text  += "\n\nJesteś na " + (scores.Scores.FindIndex(0, us => us.Score >= gameTime) + 1)
                      + " miejscu.\n\n";
         }
         int i = 0;
         if (scores.Scores.Count > 0)
         {
             text += "Wszystkie wyniki:\n" + scores.Scores
                     .Select(t => (++i) + ". " + t.Score / 24 + " dni " + t.Score % 24 + " godzin ")
                     .Aggregate((t, y) => t + "\n" + y);
         }
         OpenWindow().OpenText(text);
     }
 }
Пример #2
0
    internal static GameHighScores Save(string gameId, string gameHash, int gameScore, int returnCount)
    {
        GameHighScores allScores = Load(gameId, gameHash);

        allScores.Scores.Add(new UserScore(gameScore));
        allScores.Scores = allScores.Scores.OrderBy(x => x.Score).ToList();
        string jsoned = JsonUtility.ToJson(new HashedScores()
        {
            { gameHash, allScores }
        });

        PlayerPrefs.SetString("scores." + gameId, jsoned);
        return(allScores);
    }
Пример #3
0
        private async void GetGameScores(string gamename)
        {
            AmostiService amostiService = new AmostiService();

            GameHighScores.Clear();
            var scores = await amostiService.GetGameScores(gamename);

            RecordId = scores.First().recordId;     // Finner id til verdien med høyest score, usannsynlig unødvendig siden id ble satt av apiet
            foreach (var score in scores)
            {
                var username = score.playerName;
                var points   = score.score;
                GameHighScores.Add(new SingleGameHighScorecs()
                {
                    HighScore = points, Username = username
                });
            }
        }