public ActionResult Edit(Game game) { if (ModelState.IsValid) { _gameService.SaveGame(game); return RedirectToAction("Index"); } return View(game); }
public void SaveGame(Game game) { //TODO: need to remove this. if (game.WorldId == 0) { game.WorldId = 1; } gameRepository.SaveGame(game); statsService.CalculateAll(); }
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; }
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); }
private void calculateGeneralStats(Game game, UserStats statsA, UserStats statsB) { calculateGeneralStatsForPlayer(game, statsA); calculateGeneralStatsForPlayer(game, statsB); }
private void calculateGame(Game game, UserStats statsA, UserStats statsB) { calculateElo(game, statsA, statsB); calculateGeneralStats(game, statsA, statsB); }
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; }
public void DeleteGame(Game game) { gameRepository.DeleteGame(game.Id); }