public ActionResult NewGame(string difficulity) { GameDifficulity gameDifficulity; GameDifficulity.TryParse(difficulity, out gameDifficulity); Reset(gameDifficulity); return(MakeBord()); }
public ActionResult HighScore(string difficulity, int topX) { List <KeyValuePair <string, double> > highScore; GameDifficulity gameDifficulity; PlayerList playerList = new PlayerList(); GameDifficulity.TryParse(difficulity, out gameDifficulity); highScore = playerList.GetHighScores(gameDifficulity, topX); return(Ok(highScore)); }
public double GetAverageRounds(GameDifficulity difficulity) { double games = 0; double rounds = 0; Stats.ForEach(delegate(GameStat s) { if (s.Difficulity == difficulity && s.Status == GameStatus.Won) { games++; rounds += s.Rounds; } }); return(rounds / games); }
public void NewGame(GameDifficulity difficulity) { // bord is always 10 x 4, but have more colors at higher difficuility if (difficulity == GameDifficulity.Hard) { NewGame(10, 4, 8); } else if (difficulity == GameDifficulity.Medium) { NewGame(10, 4, 6); } else if (difficulity == GameDifficulity.Easy) { NewGame(10, 4, 4); } }
public List <KeyValuePair <string, double> > GetHighScores( GameDifficulity difficulity, int topX) { List <KeyValuePair <string, double> > playerScores = new List <KeyValuePair <string, double> >(); foreach (KeyValuePair <string, Player> player in Players) { double v = player.Value.GetWinPercentage(difficulity); KeyValuePair <string, double> p = new KeyValuePair <string, double>(player.Key, v); playerScores.Add(p); } playerScores.Sort((pair1, pair2) => pair2.Value.CompareTo(pair1.Value)); topX = Math.Min(playerScores.Count, topX); List <KeyValuePair <string, double> > highScores = playerScores.GetRange(0, topX); return(highScores); }
public double GetWinPercentage(GameDifficulity difficulity) { double games = 0; double wins = 0; Stats.ForEach(delegate(GameStat s) { if (s.Difficulity == difficulity) { games++; if (s.Status == GameStatus.Won) { wins++; } } }); return(100 * wins / games); }
public MasterMind(GameDifficulity difficulity) { NewGame(difficulity); }
private void Reset(GameDifficulity difficulity) { game = new MasterMind(difficulity); }
public void Add(GameDifficulity difficulity, int rounds, GameStatus status) { Stats.Add(new GameStat(difficulity, rounds, status)); }
public GameStat(GameDifficulity difficulity, int rounds, GameStatus status) { Difficulity = difficulity; Rounds = rounds; Status = status; }