Пример #1
0
        public static void ProcessGame(string userInput, ref int[,] matrix, IChart chart, ref int userMoves)
        {
            if (userInput == null || userInput == string.Empty
                || matrix == null || chart == null)
            {
                throw new ArgumentNullException("Input is null or with with empty value.");
            }

            switch (userInput)
            {
                case "RESTART":
                    matrix = GenerateBoard();
                    PrintBoard(matrix);
                    userMoves = 0;
                    break;

                case "TOP":
                    chart.PrintChart();
                    break;

                case "EXIT":
                    Console.WriteLine("Good Bye!");
                    break;

                default:
                    ValidateInput(userInput, matrix);
                    userMoves++;

                    bool baloonExists = CheckForBaloon(userInput, matrix);
                    if (baloonExists)
                    {
                        PopBaloons(userInput, ref matrix);
                    }
                    else
                    {
                        Console.WriteLine("Cannot pop missing ballon!");
                    }

                    bool allBaloonsArePoped = CheckForGameOver(matrix);
                    if (allBaloonsArePoped)
                    {
                        Console.WriteLine("Gratz! You completed it in {0} moves.", userMoves);

                        bool isForChart = chart.GoodEnoughForChart(userMoves);
                        if (isForChart)
                        {
                            chart.AddToChart(userMoves);
                            chart.SortChart();
                            chart.PrintChart();
                        }
                        else
                        {
                            Console.WriteLine("I am sorry you are not skillful enough for TopFive chart!");
                        }

                        matrix = GenerateBoard();
                        userMoves = 0;
                    }

                    PrintBoard(matrix);
                    break;
            }
        }