Example #1
0
    public List <HighScoreModel> CalculateTop5HighScore(int NewGameScore)
    {
        List <HighScoreModel> modelList = new List <HighScoreModel>();

        using (gameManager = new GameManager())
        {
            GameSettingsModel model = gameManager.GetGameSettingsAndHighScores();
            if (model != null && model.HighScores != null && model.HighScores.Count > 0)
            {
                model.HighScores = model.HighScores.OrderByDescending(x => x.Score).ThenByDescending(y => y.ScoreDate).ToList();
                HighScoreModel newHighScore = new HighScoreModel()
                {
                    Id = model.HighScores.Max(x => x.Id) + 1, Level = Level, Score = NewGameScore, ScoreDate = DateTime.UtcNow.ToString()
                };
                model.HighScores.Add(newHighScore);
                if (model.HighScores.Count > 5)
                {
                    model.HighScores = model.HighScores.OrderByDescending(x => x.Score).ThenByDescending(y => y.ScoreDate).ToList();
                    model.HighScores.RemoveRange(5, 1);
                }
                modelList.AddRange(model.HighScores);
            }
            else
            {
                HighScoreModel item = new HighScoreModel();
                item.Id        = 1;
                item.Level     = Level;
                item.Score     = NewGameScore;
                item.ScoreDate = DateTime.UtcNow.ToString();
                modelList.Add(item);
            }
        }

        return(modelList);
    }
Example #2
0
        // GET: Highscore
        public ActionResult Index()
        {
            var highscore = api.GetHighscore().Result;
            var model     = new HighScoreModel(highscore);

            return(View(model));
        }
Example #3
0
        public void SaveHighScore(HighScoreModel highScore)
        {
            var store = GetHighScores();

            store.Add(highScore);
            _application[KeyName] = store;
        }
Example #4
0
 public bool AddNewHighScore(HighScoreModel highScore)
 {
     if (_highScoreRepo.GetHighScoreModel(highScore) == null)
     {
         _highScoreRepo.AddHighscore(highScore);
     }
     return(_highScoreRepo.SaveChanges());
 }
Example #5
0
    private void SaveHighScore(GameStateModel game)
    {
        var highScore = new HighScoreModel
        {
            DateFinished = DateTime.Now,
            PlayerName   = game.PlayerName,
            SecondsToWin = game.RunningTime.TotalSeconds
        };

        _highScoresStore.SaveHighScore(highScore);
    }
Example #6
0
 public HighScoreModel GetHighScoreModel(HighScoreModel highScoreModel)
 {
     return(_context.HighScores.FirstOrDefault(h => h.Score == highScoreModel.Score && h.User.Equals(highScoreModel.User)));
 }
Example #7
0
 public void AddHighscore(HighScoreModel highscore)
 {
     _context.HighScores.Add(highscore);
 }