Beispiel #1
0
 public ActionResult Edit(Game game)
 {
     if (ModelState.IsValid)
     {
         _gameService.SaveGame(game);
         return RedirectToAction("Index");
     }
     return View(game);
 }
Beispiel #2
0
 public void SaveGame(Game game)
 {
     //TODO: need to remove this.
     if (game.WorldId == 0)
     {
         game.WorldId = 1;
     }
     gameRepository.SaveGame(game);
     statsService.CalculateAll();
 }
Beispiel #3
0
 private UserStats cloneNewUserStats(IEnumerable<UserStats> stats, int userId, Game game)
 {
     var stat = stats.Where(x => x.UserId == userId).OrderByDescending(x => x.CalcDate).FirstOrDefault();
     if (stat == null)
     {
         stat = new UserStats { UserId = userId };
     }
     else
     {
         stat = new UserStats
             {
                 UserId = userId,
                 Draws = stat.Draws,
                 Elo = stat.Elo,
                 Losses = stat.Losses,
                 WinRate = stat.WinRate,
                 Wins = stat.Wins,
                 Games=stat.Games
             };
     }
     stat.CalcDate = game.Date;
     stat.GameId = game.Id;
     return stat;
 }
Beispiel #4
0
 private void calculateGeneralStatsForPlayer(Game game, UserStats stats)
 {
     stats.Games++;
     if (game.ScoreA == game.ScoreB)
     {
         stats.Draws++;
     }
     else
     {
         if (game.PlayerAId == stats.UserId)
         {
             if (game.ScoreA > game.ScoreB)
             {
                 stats.Wins++;
             }
             else
             {
                 stats.Losses++;
             }
         }
         else
         {
             if (game.ScoreB > game.ScoreA)
             {
                 stats.Wins++;
             }
             else
             {
                 stats.Losses++;
             }
         }
     }
     stats.WinRate = decimal.Round((stats.Wins * 1.0000m + stats.Draws * 0.5000m) / stats.Games * 100, 2);
 }
Beispiel #5
0
 private void calculateGeneralStats(Game game, UserStats statsA, UserStats statsB)
 {
     calculateGeneralStatsForPlayer(game, statsA);
     calculateGeneralStatsForPlayer(game, statsB);
 }
Beispiel #6
0
 private void calculateGame(Game game, UserStats statsA, UserStats statsB)
 {
     calculateElo(game, statsA, statsB);
     calculateGeneralStats(game, statsA, statsB);
 }
Beispiel #7
0
        private void calculateElo(Game game, UserStats statsA, UserStats statsB)
        {
            var elo = new EloCalculator(statsA.Elo, statsB.Elo);
            if (game.ScoreA > game.ScoreB)
            {
                elo.WinGamePlayerA();
            }
            else if (game.ScoreA < game.ScoreB)
            {
                elo.WinGamePlayerB();
            }
            else
            {
                elo.DrawGame();
            }

            statsA.Elo = (decimal)elo.RatingPlayerA;
            statsB.Elo = (decimal)elo.RatingPlayerB;
        }
Beispiel #8
0
 public void DeleteGame(Game game)
 {
     gameRepository.DeleteGame(game.Id);
 }