/// <summary>
 /// Initializes a new instance of the <see cref="DefaultGameCommandExecutor" /> class.
 /// </summary>
 /// <param name="renderer">The game renderer.</param>
 /// <param name="inputMethod">The input method.</param>
 /// <param name="scores">The high scores.</param>
 public DefaultGameCommandExecutor(IRenderer renderer, IInputMethod inputMethod, HighScores scores)
 {
     this.scores = scores;
     this.gameRenderer = renderer;
     this.inputMethod = inputMethod;
     this.GenerateNewBoard(MaxRows, MaxColumns, MaxMines);
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameEngine" /> class.
 /// </summary>
 /// <param name="renderer">The game renderer.</param>
 /// <param name="inputMethod">The user input method.</param>
 public GameEngine(IRenderer renderer, IInputMethod inputMethod)
 {
     this.gameRenderer = renderer;
     this.inputMethod = inputMethod;
     this.scores = new HighScores(MaxTopPlayers);
     this.cmdExecutor = new DefaultGameCommandExecutor(this.gameRenderer, this.inputMethod, this.scores);
 }
 public void TestIsHighScore()
 {
     HighScores higScoresList = new HighScores(2);
     bool actual = higScoresList.IsHighScore(12);
     bool expected = true;
     Assert.AreEqual(expected, actual);
 }
 public void TestIsHighScoreWithFullScoreList2()
 {
     HighScores higScoresList = new HighScores(2);
     higScoresList.AddTopScore(new Player("a", 10));
     higScoresList.AddTopScore(new Player("b", 2));
     bool actual = higScoresList.IsHighScore(1);
     bool expected = false;
     Assert.AreEqual(expected, actual);
 }
        public void TestDisplayTopScores1()
        {
            HighScores higScoresList = new HighScores(3);
            higScoresList.AddTopScore(new Player("e", 17));
            higScoresList.AddTopScore(new Player("e", 0));
            StringBuilder result = new StringBuilder();
            result.AppendLine("1. e --> 17");
            result.AppendLine("2. e --> 0");
            string expected = result.ToString();
            string actual = higScoresList.GetTopScores();

            Assert.AreEqual(expected, actual);
        }
        public void TestDisplayTopScores2()
        {
            HighScores higScoresList = new HighScores(3);
            higScoresList.AddTopScore(new Player("a", 1));
            higScoresList.AddTopScore(new Player("b", 12));
            higScoresList.AddTopScore(new Player("c", 102));
            higScoresList.AddTopScore(new Player("b", 19));
            StringBuilder result = new StringBuilder();
            result.Append("1. c --> 102\r\n");
            result.Append("2. b --> 19\r\n");
            result.Append("3. b --> 12\r\n");
            string expected = result.ToString();
            string actual = higScoresList.GetTopScores();

            Assert.AreEqual(expected, actual);
        }
 public void TestCmdExecutorFiveScores()
 {
     HighScores scores = new HighScores(5);
     scores.ProcessScore("pesho", 100);
     scores.ProcessScore("ivan", 80);
     scores.ProcessScore("gosho", 70);
     scores.ProcessScore("stamat", 60);
     scores.ProcessScore("petkan", 50);
     DefaultGameCommandExecutor cmdExecutor = new DefaultGameCommandExecutor(mockRenderer, mockInputMethod, scores);
     cmdExecutor.DisplayTopScores();
     string scoreMessage = mockRenderer.GetMessage();
     StringBuilder expectedScoreMessage = new StringBuilder();
     expectedScoreMessage.Append("Scoreboard");
     expectedScoreMessage.AppendLine("1. pesho --> 100");
     expectedScoreMessage.AppendLine("2. ivan --> 80");
     expectedScoreMessage.AppendLine("3. gosho --> 70");
     expectedScoreMessage.AppendLine("4. stamat --> 60");
     expectedScoreMessage.AppendLine("5. petkan --> 50");
     Assert.AreEqual(expectedScoreMessage.ToString(), scoreMessage, "The message when the input is invalid is incorrect!");
 }
 public void TestProcessScore()
 {
     HighScores higScoresList = new HighScores(2);
     higScoresList.AddTopScore(new Player("a", 10));
     higScoresList.AddTopScore(new Player("b", 2));
     higScoresList.ProcessScore("mimi", 15);
     StringBuilder result = new StringBuilder();
     result.Append("1. mimi --> 15\r\n");
     result.Append("2. a --> 10\r\n");
     string expected = result.ToString();
     string actual = higScoresList.GetTopScores();
     Assert.AreEqual(expected, actual);
 }
 public void TestAddScoreNullValue()
 {
     HighScores higScoresList = new HighScores(2);
     higScoresList.AddTopScore(null);
 }
 public void TestProcessScoreWithNegativeScore()
 {
     HighScores higScoresList = new HighScores(2);
     higScoresList.AddTopScore(new Player("a", 10));
     higScoresList.AddTopScore(new Player("b", 2));
     higScoresList.ProcessScore("mimi", -15);
 }