Esempio n. 1
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;
            }
        }
Esempio n. 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;
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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());
        }
Esempio n. 5
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 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);
        }