예제 #1
0
        private void GetLower()
        {
            if (Math.Max(Math.Max(currentFigure.PosFirstY, currentFigure.PosSecondY),
                         Math.Max(currentFigure.PosThirdY, currentFigure.PosQuadrupleY)) <
                board.GetLength(1) - 1 &&
                board[currentFigure.PosFirstX, currentFigure.PosFirstY + 1] != 1 &&
                board[currentFigure.PosSecondX, currentFigure.PosSecondY + 1] != 1 &&
                board[currentFigure.PosThirdX, currentFigure.PosThirdY + 1] != 1 &&
                board[currentFigure.PosQuadrupleX, currentFigure.PosQuadrupleY + 1] != 1)
            {
                currentFigure.GetLower();
            }
            else
            {
                board[currentFigure.PosFirstX, currentFigure.PosFirstY]         = 1;
                board[currentFigure.PosSecondX, currentFigure.PosSecondY]       = 1;
                board[currentFigure.PosThirdX, currentFigure.PosThirdY]         = 1;
                board[currentFigure.PosQuadrupleX, currentFigure.PosQuadrupleY] = 1;

                currentFigure = nextFigure;

                if (board[currentFigure.PosFirstX, currentFigure.PosFirstY] == 1 ||
                    board[currentFigure.PosSecondX, currentFigure.PosSecondY] == 1 ||
                    board[currentFigure.PosThirdX, currentFigure.PosThirdY] == 1 ||
                    board[currentFigure.PosQuadrupleX, currentFigure.PosQuadrupleY] == 1)
                {
                    GameOver();
                }

                nextFigure = figureCreator.Create();
                pictureBox2.Invalidate();

                //построчная проверка заполненности ряда доски
                for (int i = 0; i < board.GetLength(1); i++)
                {
                    int j = 0;

                    while (j < board.GetLength(0) && board[j, i] == 1)
                    {
                        j++;
                    }
                    //если все ячейки в строке заполнены, то сдвигаем все ряды на 1 вниз
                    if (j == board.GetLength(0))
                    {
                        Settings.Score += 1;
                        label2.Text     = $"{Settings.Score}";
                        for (int k = i; k > 0; k--)
                        {
                            for (int l = 0; l < board.GetLength(0); l++)
                            {
                                board[l, k] = board[l, k - 1];
                            }
                        }
                        for (int l = 0; l < board.GetLength(0); l++)
                        {
                            board[l, 0] = 0;
                        }
                    }
                }
            }
        }