public void CheckMoveValidityInputEmpty()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            bool result = game.CheckMoveValidity(string.Empty);

            Assert.AreEqual(false, result, "Invalid input cell!");
        }
예제 #2
0
        /// <summary>
        /// Executes a command from a predefined set of commands or breaks if invalid command.
        /// </summary>
        /// <param name="game">Instace of the BalloonsEngine class.</param>
        /// <param name="command">User input command to execute.</param>
        private static void ExecuteCommand(BalloonsEngine game, string command)
        {
            switch (command)
            {
                case "restart":
                    Console.WriteLine();
                    PrintIntroMessage();
                    game.RestartGame();
                    Console.WriteLine(game.FieldOutput());
                    break;

                case "top":
                    Console.WriteLine(game.GenerateChart());
                    break;

                case "exit":
                    PrintExitMessage();
                    break;

                default:
                    if (game.CheckMoveValidity(command))
                    {
                        ProcessMove(command, game);
                    }
                    else
                    {
                        PrintInvalidCommandMessage();
                    }

                    break;
            }
        }
        public void CheckMoveValidityInput49()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            bool result = game.CheckMoveValidity("4 9");

            Assert.AreEqual(true, result, "Invalid input cell!");
        }
예제 #4
0
        /// <summary>
        /// Executes a command from a predefined set of commands or breaks if invalid command.
        /// </summary>
        /// <param name="game">Instace of the BalloonsEngine class.</param>
        /// <param name="command">User input command to execute.</param>
        private static void ExecuteCommand(BalloonsEngine game, string command)
        {
            switch (command)
            {
            case "restart":
                Console.WriteLine();
                PrintIntroMessage();
                game.RestartGame();
                Console.WriteLine(game.FieldOutput());
                break;

            case "top":
                Console.WriteLine(game.GenerateChart());
                break;

            case "exit":
                PrintExitMessage();
                break;

            default:
                if (game.CheckMoveValidity(command))
                {
                    ProcessMove(command, game);
                }
                else
                {
                    PrintInvalidCommandMessage();
                }

                break;
            }
        }
예제 #5
0
        public static int[,] GenerateFieldShim(BalloonsEngine game, int row, int col)
        {
            expectedRow = row;
            expectedCol = col;

            return GetFieldFromXML(row, col);
        }
예제 #6
0
        public void ChartPlacementAfter5()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            game.UserMoves = 5;
            for (int i = 0; i < 5; i++)
            {
                game.UserMoves++;
                game.RecordHighscore(i.ToString(), game.ChartPlaceIndex());
            }

            game.UserMoves = 1;
            game.RecordHighscore("FirstPlace", game.ChartPlaceIndex());

            StringBuilder expectedBuilder = new StringBuilder();
            expectedBuilder.AppendLine("---------TOP FIVE CHART-----------");
            expectedBuilder.AppendFormat("{2}. {0} with {1} moves.\n", "FirstPlace", 1, 1);
            for (int i = 2; i <= 5; i++)
            {
                expectedBuilder.AppendFormat("{2}. {0} with {1} moves.\n", (i - 2).ToString(), i + 4, i);
            }

            expectedBuilder.AppendLine("----------------------------------");

            Assert.AreEqual(expectedBuilder.ToString(), game.GenerateChart());
        }
        public void CheckMoveValidityInputNegativeNum()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            bool result = game.CheckMoveValidity("-2 -1");

            Assert.AreEqual(false, result, "Invalid input cell!");
        }
        public void FieldOutputLength()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            string outputField = game.FieldOutput();

            Assert.AreEqual(217, outputField.Length);
        }
        public void CheckIfWinningOutputTrue()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);

            TestUtils.PopAllBalloons(game);
            bool result = game.CheckIfWinning();

            Assert.AreEqual(true, result);
        }
        public void CheckIfWinningOutputFalse()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            game.TryPopBalloons(2, 6);
            game.TryPopBalloons(1, 8);
            bool result = game.CheckIfWinning();

            Assert.AreEqual(false, result);
        }
예제 #11
0
        public void GenerateChartOutputWithoutTop()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            game.TryPopBalloons(2, 6);
            string result = game.GenerateChart();

            StringBuilder expectedResult = new StringBuilder();
            expectedResult.AppendLine("The scoreboard is empty.");

            Assert.AreEqual(expectedResult.ToString(), result);
        }
예제 #12
0
 public static void PopAllBalloons(BalloonsEngine game)
 {
     for (int i = 0; i < game.FieldRows; i++)
     {
         for (int j = 0; j < game.FieldColumns; j++)
         {
             game.TryPopBalloons(i, j);
             game.UserMoves++;
             game.CollapseRows();
         }
     }
 }
예제 #13
0
        /// <summary>
        /// The entry point of the program.
        /// </summary>
        static void Main(string[] args)
        {
            string userInput = string.Empty;

            BalloonsEngine game = new BalloonsEngine(5, 10);

            PrintIntroMessage();
            Console.WriteLine(game.FieldOutput());

            while (userInput != "exit")
            {
                PrintMoveMessage();
                userInput = GetInput();

                ExecuteCommand(game, userInput);
            }
        }
예제 #14
0
        public void GenerateChartOutputWithTop()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);

            TestUtils.PopAllBalloons(game);
            int place = game.ChartPlaceIndex();
            string result = string.Empty;
            if (place != -1)
            {
                game.RecordHighscore("Bunny", place);
                result = game.GenerateChart();
            }

            StringBuilder expectedResult = new StringBuilder();
            expectedResult.AppendLine("---------TOP FIVE CHART-----------");
            expectedResult.AppendFormat("{2}. {0} with {1} moves.\n", "Bunny", game.UserMoves, 1);
            expectedResult.AppendLine("----------------------------------");

            Assert.AreEqual(expectedResult.ToString(), result);
        }
예제 #15
0
        public void PopFirstRowAndCol()
        {
            using (ShimsContext.Create())
            {
                BalloonsEngine game = new BalloonsEngine(0, 0);

                ShimBalloonsEngine.AllInstances.GeneratePlayFieldInt32Int32
                = (game1, x, y) => TestUtils.GenerateFieldShim(game, 5, 10);

                TestUtils.FileName("01.AllOnesInput.xml");
                game = new BalloonsEngine(5, 10);
                game.TryPopBalloons(0, 0);

                int[,] gameField = (int[,])typeof(BalloonsEngine).GetField("playField", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(game);
                int[,] expectedOutput = TestUtils.GetExpectedOutput();

                bool valuesAreEqual = TestUtils.CheckPlayFields(gameField, expectedOutput);

                Assert.AreEqual(valuesAreEqual, true, "First row and col of balloons weren't popped.");
            }
        }
예제 #16
0
        public void CollapseRows()
        {
            using (ShimsContext.Create())
            {
                BalloonsEngine game = new BalloonsEngine(0, 0);

                ShimBalloonsEngine.AllInstances.GeneratePlayFieldInt32Int32
                = (game1, x, y) => TestUtils.GenerateFieldShim(game, 5, 10);

                TestUtils.FileName("07.CollapseInput.xml");
                game = new BalloonsEngine(5, 10);
                game.CollapseRows();

                int[,] gameField = (int[,])typeof(BalloonsEngine).GetField("playField", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(game);
                int[,] expectedOutput = TestUtils.GetExpectedOutput();

                bool valuesAreEqual = TestUtils.CheckPlayFields(gameField, expectedOutput);

                Assert.AreEqual(valuesAreEqual, true);
            }
        }
예제 #17
0
        /// <summary>
        /// Processes the move entered by the player.
        /// </summary>
        /// <param name="userInput">Row and column of the move.</param>
        /// <param name="game">Instace of the BalloonsEngine class.</param>
        private static void ProcessMove(string userInput, BalloonsEngine game)
        {
            int userRow, userColumn;

            userRow    = ConvertCharToInt(userInput[0]);
            userColumn = ConvertCharToInt(userInput[2]);

            if (!game.TryPopBalloons(userRow, userColumn))
            {
                PrintIllegalMoveMessage();
            }

            game.UserMoves++;
            game.CollapseRows();

            if (game.CheckIfWinning())
            {
                Console.WriteLine(game.FieldOutput());
                Console.WriteLine("Congratulations! You popped all baloons in {0} moves.", game.UserMoves);

                int place = game.ChartPlaceIndex();
                if (place != -1)
                {
                    Console.WriteLine("Please enter your name for the top scoreboard: ");
                    string username = Console.ReadLine();
                    game.RecordHighscore(username, place);
                    Console.WriteLine(game.GenerateChart());
                }
                else
                {
                    Console.WriteLine("Game Over!");
                    Console.WriteLine(game.GenerateChart());
                }

                game.RestartGame();
            }

            Console.WriteLine(game.FieldOutput());
        }
예제 #18
0
        public void ChartPlaceIndexOutput()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);

            TestUtils.PopAllBalloons(game);
            int placeResult = game.ChartPlaceIndex();
            if (placeResult != -1)
            {
                game.RecordHighscore("Bunny", placeResult);
            }
            game.RestartGame();

            TestUtils.PopAllBalloons(game);
            placeResult = game.ChartPlaceIndex();
            if (placeResult != -1)
            {
                game.RecordHighscore("Sunny", placeResult);
            }
            game.RestartGame();
            TestUtils.PopAllBalloons(game);
            placeResult = game.ChartPlaceIndex();

            Assert.AreEqual(2, placeResult);
        }
 public void CheckMoveValidityInputNull()
 {
     BalloonsEngine game = new BalloonsEngine(5, 10);
     game.CheckMoveValidity(null);
 }
        public void FieldOutputRestartGame()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            game.TryPopBalloons(2, 5);
            game.TryPopBalloons(4, 1);
            int outputFieldLength = game.FieldOutput().Length;
            game.RestartGame();
            int outputFieldLengthAfterRestart = game.FieldOutput().Length;

            Assert.AreEqual(outputFieldLength, outputFieldLengthAfterRestart);
        }
        public void TryPopBalloonsOutputFalse()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            game.TryPopBalloons(0, 7);
            bool result = game.TryPopBalloons(0, 7);

            Assert.AreEqual(false, result);
        }
        public void TryPopBalloonsOutputTrue()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            bool result = game.TryPopBalloons(1, 2);

            Assert.AreEqual(true, result);
        }
예제 #23
0
        /// <summary>
        /// Processes the move entered by the player.
        /// </summary>
        /// <param name="userInput">Row and column of the move.</param>
        /// <param name="game">Instace of the BalloonsEngine class.</param>
        private static void ProcessMove(string userInput, BalloonsEngine game)
        {
            int userRow, userColumn;
            userRow = ConvertCharToInt(userInput[0]);
            userColumn = ConvertCharToInt(userInput[2]);

            if (!game.TryPopBalloons(userRow, userColumn))
            {
                PrintIllegalMoveMessage();
            }

            game.UserMoves++;
            game.CollapseRows();

            if (game.CheckIfWinning())
            {
                Console.WriteLine(game.FieldOutput());
                Console.WriteLine("Congratulations! You popped all baloons in {0} moves.", game.UserMoves);

                int place = game.ChartPlaceIndex();
                if (place != -1)
                {
                    Console.WriteLine("Please enter your name for the top scoreboard: ");
                    string username = Console.ReadLine();
                    game.RecordHighscore(username, place);
                    Console.WriteLine(game.GenerateChart());
                }
                else
                {
                    Console.WriteLine("Game Over!");
                    Console.WriteLine(game.GenerateChart());
                }

                game.RestartGame();
            }

            Console.WriteLine(game.FieldOutput());
        }
        public void FieldOutputLengthAfterMove()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            game.TryPopBalloons(0, 0);
            game.TryPopBalloons(4, 9);
            string outputField = game.FieldOutput();

            Assert.AreEqual(217, outputField.Length);
        }
예제 #25
0
        /// <summary>
        /// The entry point of the program.
        /// </summary>
        static void Main(string[] args)
        {
            string userInput = string.Empty;

            BalloonsEngine game = new BalloonsEngine(5, 10);

            PrintIntroMessage();
            Console.WriteLine(game.FieldOutput());

            while (userInput != "exit")
            {
                PrintMoveMessage();
                userInput = GetInput();

                ExecuteCommand(game, userInput);
            }
        }
예제 #26
0
        public void PopFourthRowAndNinthCol()
        {
            using (ShimsContext.Create())
            {
                BalloonsEngine game = new BalloonsEngine(0, 0);

                ShimBalloonsEngine.AllInstances.GeneratePlayFieldInt32Int32
                = (game1, x, y) => TestUtils.GenerateFieldShim(game, 5, 10);

                TestUtils.FileName("04.AllOnesInput.xml");
                game = new BalloonsEngine(5, 10);
                game.TryPopBalloons(4, 9);
                game.CollapseRows();

                int[,] gameField = (int[,])typeof(BalloonsEngine).GetField("playField", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(game);
                int[,] expectedOutput = TestUtils.GetExpectedOutput();

                bool valuesAreEqual = TestUtils.CheckPlayFields(gameField, expectedOutput);

                Assert.AreEqual(valuesAreEqual, true, "Fourth row and 9th col didn't pop and collapse properly.");
            }
        }