Пример #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;
            }
        }
Пример #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 FieldOutputLength()
        {
            BalloonsEngine game = new BalloonsEngine(5, 10);
            string outputField = game.FieldOutput();

            Assert.AreEqual(217, outputField.Length);
        }
Пример #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());
        }
Пример #5
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);
            }
        }
Пример #6
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);
            }
        }
Пример #7
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);
        }
        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);
        }