public void ShouldPrintSampleScoreboardMessage_TopCommandTest()
        {
            Player firstPlayer = new Player();
            firstPlayer.Name = "Pesho";
            firstPlayer.TotalMoves = 4;
            GameEngine testEngine = new GameEngine(firstPlayer);
            List<Player> topPlayersScores = new List<Player>();

            Player secondPlayer=new Player();
            secondPlayer.Name = "Spiro";
            secondPlayer.TotalMoves = 6;

            topPlayersScores.Add(firstPlayer);
            topPlayersScores.Add(secondPlayer);

            ICommand topCommand = new TopCommand(topPlayersScores);
            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                testEngine.CommandManager.Proceed(topCommand);

                writer.Flush();

                string result = writer.GetStringBuilder().ToString();
                string expected = "\nScoreboard:\r\nPesho by 4\r\nSpiro by 6\r\n\r\n";
                Assert.AreEqual(expected, result);
            }
        }
        public void ShouldReturnTrue_IsGameOver_ExitCommandTest()
        {
            Player testPlayer =new Player();
            GameEngine testEngine = new GameEngine(testPlayer);
            ICommand exitCommand = new ExitCommand(testEngine);
            testEngine.CommandManager.Proceed(exitCommand);

            Assert.IsTrue(testEngine.IsGameOver);
        }
コード例 #3
0
 /// <summary>
 /// Initialize a new instance of the GameEngine class
 /// </summary>
 public GameEngine(Player player)
 {
     this.Player = player;
     this.PuzzleField = PuzzleField.GetInstance(MatrixSize); // using Singleton design pattern
     this.CommandManager = new CommandManager();
     this.PuzzleFieldManager = new PuzzleFieldManager(this.PuzzleField);
     this.ShuffleStrategy = new RandomShuffle();
     this.IsGameOver = false;
     this.TopPlayers = new List<Player>();
 }
        public void ShouldReturnTrue_RestartCommandTest_ChangeCountTotalMoves()
        {
            Player testPlayer = new Player();
            GameEngine testEngine = new GameEngine(testPlayer);
            testEngine.Player.TotalMoves = 2;
            ICommand restartCommand = new RestartCommand(testEngine);
            testEngine.CommandManager.Proceed(restartCommand);

            Assert.IsTrue(testEngine.Player.TotalMoves == 0);
        }
        public void ShouldPrintEmptyScoreboardMessage_TopCommandTest()
        {
            Player testPlayer = new Player();
            GameEngine testEngine = new GameEngine(testPlayer);
            List<Player> topPlayersScores = new List<Player>();
            ICommand topCommand = new TopCommand(topPlayersScores);
            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                testEngine.CommandManager.Proceed(topCommand);

                writer.Flush();

                string result = writer.GetStringBuilder().ToString();
                string expected = "\nScoreboard:\r\nEmpty Scoreboard! :)\r\n\r\n";
                Assert.AreEqual(expected, result);
            }
        }
        public void ShouldPrintFinalMessage_ExitCommandTest()
        {
            Player testPlayer = new Player();
            GameEngine testEngine = new GameEngine(testPlayer);
            ICommand exitCommand = new ExitCommand(testEngine);

            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                testEngine.CommandManager.Proceed(exitCommand);

                writer.Flush();

                string result = writer.GetStringBuilder().ToString();
                string expected = "Good bye!\r\n";
                Assert.AreEqual(expected, result);
            }
        }
コード例 #7
0
        public void ShouldReturnTrue_CheckIsIncreaseTotalMovesOfPlayer()
        {
            Player testPlayer = new Player();
            GameEngine testEngine = new GameEngine(testPlayer);
            var oldIn = Console.In;
            Console.SetIn(new StringReader("5\r\nexit"));
            string result = String.Empty;
            using (var writer = new StringWriter())
            {
                Console.SetOut(writer);
                testEngine.StartTheGame();

                writer.Flush();

                result = writer.GetStringBuilder().ToString();
            }
            Console.SetIn(oldIn);
            int expectedPlayerMoves = 1;
            string expectedMessage = "Illegal move!\r\nEnter a number to move: Good bye!\r\n";
            string resultString = result.Substring(result.Length - 50);
            Assert.IsTrue(expectedPlayerMoves == testPlayer.TotalMoves || expectedMessage == resultString);

        }
コード例 #8
0
 /// <summary>
 /// This method call StartTheGame() method of GameEngine class.
 /// </summary>
 public static void Main()
 {
     Player currentPlayer = new Player();
     GameEngine gameEngine = new GameEngine(currentPlayer);
     gameEngine.StartTheGame();
 }
コード例 #9
0
        /// <summary>
        /// This method add new top player in top players rank list at end of the game.
        /// </summary>
        /// <param name="inputOfPlayerName">Name of the player.</param>
        private void AddNewTopPlayer(Player currentPlayer)
        {
            this.TopPlayers.Add(currentPlayer);
            this.TopPlayers.Sort((a, b) => a.TotalMoves.CompareTo(b.TotalMoves));

            if (this.TopPlayers.Count == 4)
            {
                this.TopPlayers.RemoveAt(3);
            }
        }
 public void ShouldReturnTrue_DefineCommandsMethodTest()
 {
     Player testPlayer = new Player();
     GameEngine testEngine = new GameEngine(testPlayer);
     List<Player> testTopPlayers = new List<Player>();
 }