コード例 #1
0
        static void FallingDownBalloons(byte[,] matrix)
        {
            byte[,] newMatrix = matrix;
            Stack <byte> stack = new Stack <byte>();

            for (int col = 0; col < MatrixUtils.Columns; col++)
            {
                for (int row = 0; row < MatrixUtils.Rows; row++)
                {
                    if (matrix[row, col] != 0)
                    {
                        stack.Push(matrix[row, col]);
                    }
                }

                for (int row = MatrixUtils.Rows - 1; row >= 0; row--)
                {
                    try
                    {
                        newMatrix[row, col] = stack.Pop();
                    }
                    catch (Exception)
                    {
                        matrix[row, col] = 0;
                    }
                }
            }

            MatrixUtils.PrintMatrix(newMatrix);
        }
コード例 #2
0
        public static void ProcessGame(string input, string[,] topFive, ref byte[,] matrix, ref int userMoves)
        {
            switch (input)
            {
            case "RESTART":
                StartGame.Start();
                break;

            case "TOP":
                sortAndPrintChartFive(topFive);
                break;

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

            default:
                if ((input.Length == 3) && (input[0] >= '0' && input[0] <= '4') && (input[2] >= '0' && input[2] <= '9') &&
                    (input[1] == ' ' || input[1] == '.' || input[1] == ','))
                {
                    int userRow    = (int)char.GetNumericValue(input[0]);
                    int userColumn = (int)char.GetNumericValue(input[2]);

                    PopBalloon(matrix, userRow, userColumn);
                    userMoves++;

                    if (MatrixUtils.CheckMatrixIsEmpty(matrix))
                    {
                        Console.WriteLine("Congratulations! You popped all balloons in {0} moves.", userMoves);
                        if (signIfSkilled(topFive, userMoves))
                        {
                            sortAndPrintChartFive(topFive);
                        }
                        else
                        {
                            Console.WriteLine("I am sorry you are not skillful enough for TopFive chart!");
                        }
                    }
                    else
                    {
                        FallingDownBalloons(matrix);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid move or command!");
                }

                break;
            }
        }
コード例 #3
0
ファイル: StartGame.cs プロジェクト: HQ-MALEFICENT/MALEFICENT
        public static void Start()
        {
            Console.WriteLine(
                "\nWelcome to \"Balloons Pops\" game. Please try to pop the balloons. Use 'top' to view the top scoreboard, 'restart' to start a new game and 'exit' to quit the game.");

            byte[,] matrix = MatrixUtils.CreateMatrix();

            MatrixUtils.PrintMatrix(matrix);
            string input;
            int    userMoves = 0;

            while (true)
            {
                Console.Write("Enter a row and column: ");
                input = Console.ReadLine();
                input = input.ToUpper().Trim();

                GamePlay.ProcessGame(input, TopFive, ref matrix, ref userMoves);
            }
        }