コード例 #1
0
        public ActionResult NewGame(string difficulity)
        {
            GameDifficulity gameDifficulity;

            GameDifficulity.TryParse(difficulity, out gameDifficulity);
            Reset(gameDifficulity);
            return(MakeBord());
        }
コード例 #2
0
        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));
        }
コード例 #3
0
ファイル: Player.cs プロジェクト: jancr/MasterMind
        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);
        }
コード例 #4
0
ファイル: MasterMind.cs プロジェクト: jancr/MasterMind
 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);
     }
 }
コード例 #5
0
ファイル: Player.cs プロジェクト: jancr/MasterMind
        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);
        }
コード例 #6
0
ファイル: Player.cs プロジェクト: jancr/MasterMind
        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);
        }
コード例 #7
0
ファイル: MasterMind.cs プロジェクト: jancr/MasterMind
 public MasterMind(GameDifficulity difficulity)
 {
     NewGame(difficulity);
 }
コード例 #8
0
 private void Reset(GameDifficulity difficulity)
 {
     game = new MasterMind(difficulity);
 }
コード例 #9
0
ファイル: Player.cs プロジェクト: jancr/MasterMind
 public void Add(GameDifficulity difficulity, int rounds, GameStatus status)
 {
     Stats.Add(new GameStat(difficulity, rounds, status));
 }
コード例 #10
0
ファイル: Player.cs プロジェクト: jancr/MasterMind
 public GameStat(GameDifficulity difficulity, int rounds, GameStatus status)
 {
     Difficulity = difficulity;
     Rounds      = rounds;
     Status      = status;
 }