Пример #1
0
 // Метод, отвечающий за движение фигуры вправо.
 public static void MoveRight(ITetramino currentFigure, bool[,] buildingArea)
 {
     if (MoveRightCheck(currentFigure, buildingArea))
     {
         currentFigure.CurrentCol++;
     }
 }
Пример #2
0
        //Метод, описывающий условие конца игры.
        public bool GameOver(ITetramino currentFigure, bool[,] buildingArea)
        {
            bool gameOver = false;

            if (currentFigure.CurrentRow == 0)
            {
                for (int row = 0; row < currentFigure.Body.GetLength(0); row++)
                {
                    for (int col = 0; col < currentFigure.Body.GetLength(1); col++)
                    {
                        if (currentFigure.Body[row, col] == true & buildingArea[currentFigure.CurrentRow + row, currentFigure.CurrentCol + col] == true)
                        {
                            return(true);
                        }
                        else
                        {
                            gameOver = false;
                        }
                    }
                }
            }
            else
            {
                gameOver = false;
            }
            return(gameOver);
        }
Пример #3
0
        // Метод, отвечающий за проверку возможности движения фигуры вправо.
        public static bool MoveRightCheck(ITetramino currentFigure, bool[,] buildingArea)
        {
            bool moveRightCheck = true;

            for (int i = 0; i < currentFigure.Body.GetLength(0); i++)
            {
                if (moveRightCheck == false)
                {
                    break;
                }
                else
                {
                    if (currentFigure.CurrentCol + currentFigure.Body.GetLength(1) < buildingArea.GetLength(1) &&
                        buildingArea[currentFigure.CurrentRow + i, currentFigure.CurrentCol + currentFigure.Body.GetLength(1)] == false)
                    {
                        moveRightCheck = true;
                    }
                    else
                    {
                        moveRightCheck = false;
                    }
                }
            }
            return(moveRightCheck);
        }
Пример #4
0
        // Метод, отвечающий за проверку возможности движения фигуры влево.
        public static bool MoveLeftCheck(ITetramino currentFigure, bool[,] buildingArea)
        {
            bool moveLeftCheck = true;

            for (int i = 0; i < currentFigure.Body.GetLength(0); i++)
            {
                if (moveLeftCheck == false)
                {
                    break;
                }
                else
                {
                    if (currentFigure.CurrentCol > 0 &&                                                     //Если фигура не нарушает левую границу поля
                        buildingArea[currentFigure.CurrentRow + i, currentFigure.CurrentCol - 1] == false)  //и с левой от нее стороны нет построенных блоков,
                    {
                        moveLeftCheck = true;                                                               //то возвращаем "истина" (можно двигать влево).
                    }
                    else
                    {
                        moveLeftCheck = false;
                    }
                }
            }
            return(moveLeftCheck);
        }
Пример #5
0
 // Метод, отвечающий за движение фигуры влево.
 public static void MoveLeft(ITetramino currentFigure, bool[,] buildingArea)
 {
     if (MoveLeftCheck(currentFigure, buildingArea))                                                 //Проверяем на предмет ошибок при движении фигуры влево.
     {
         currentFigure.CurrentCol--;
     }
 }
Пример #6
0
 //Метод, отвечающий за размещение фигуры среди построенных блоков.
 public void PlaceCurrentFigure(ITetramino currentFigure, bool[,] buildingArea)
 {
     for (int row = 0; row < currentFigure.Body.GetLength(0); row++)
     {
         for (int col = 0; col < currentFigure.Body.GetLength(1); col++)
         {
             if (currentFigure.Body[row, col])
             {
                 buildingArea[currentFigure.CurrentRow + row, currentFigure.CurrentCol + col] = true;
             }
         }
     }
 }
Пример #7
0
 public static void Draw(int xAxis, int yAxis, ITetramino figure)
 {
     for (int row = 0; row < figure.Body.GetLength(0); row++)
     {
         for (int col = 0; col < figure.Body.GetLength(1); col++)
         {
             if (figure.Body[row, col] == true)
             {
                 Console.SetCursorPosition(xAxis + col, yAxis + row);
                 Console.Write("*");
             }
         }
     }
 }
Пример #8
0
        public ITetramino GenerateFigure()
        {
            _listOfTetramino = new List <ITetramino>()
            {
                new Ltetra(), new Jtetra(), new Ztetra(),
                new Stetra(), new Ttetra(), new Itetra(),
                new Otetra()
            };
            ITetramino temp = _listOfTetramino[blessRng.Next(_listOfTetramino.Count)];

            temp.CurrentRow = 0;
            temp.CurrentCol = 4;
            return(temp);
        }
Пример #9
0
 //Метод, отвечающий за отрисовку информационной панели.
 public void DrawInfoArea(ITetramino nextFigure, GameData gd)
 {
     ClearInfoArea(InfoAreaCol + 4, 3);
     Console.SetCursorPosition(InfoAreaCol, 1);
     Console.Write("Следующая:");
     DrawTetra.Draw(InfoAreaCol + 4, 3, nextFigure);
     Console.SetCursorPosition(InfoAreaCol, 8);
     Console.Write("Очки: {0}", gd.Points);
     Console.SetCursorPosition(InfoAreaCol, 10);
     Console.Write("Линии: {0}", gd.CompletedLinesNumber);
     Console.SetCursorPosition(InfoAreaCol, 12);
     Console.Write("Время: {0:00}:{1:00}", gd.Time.Minutes, gd.Time.Seconds);
     Console.SetCursorPosition(InfoAreaCol, 15);
     Console.Write(Message[gd.LastStreak]);
 }
Пример #10
0
        //Проверка на столкновение текущей фигуры с построенными блоками.
        public bool IntersectionCheck(ITetramino currentFigure, bool[,] buildingArea)
        {
            if (currentFigure.CurrentRow + currentFigure.Body.GetLength(0) >= buildingArea.GetLength(0))
            {
                return(true);
            }

            for (int row = 0; row < currentFigure.Body.GetLength(0); row++)
            {
                for (int col = 0; col < currentFigure.Body.GetLength(1); col++)
                {
                    int lowestBuildingRow = currentFigure.CurrentRow + row + 1;

                    if (currentFigure.Body[row, col] == true &
                        buildingArea[lowestBuildingRow, currentFigure.CurrentCol + col] == true)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #11
0
        // Метод, отвечающий за поворот фигуры по часовой стрелке.
        public static void RotateRight(ITetramino currentFigure, bool[,] buildingArea)
        {
            int nextState = currentFigure.State;

            if (currentFigure.State + 1 > currentFigure.CountState)
            {
                nextState = 1;
            }
            else
            {
                nextState++;
            }
            ITetramino nextStateCurFig = (ITetramino)currentFigure.Clone();

            nextStateCurFig.Body = currentFigure.FigureState[nextState];

            if (RotateCheck(nextStateCurFig, buildingArea))
            {
                currentFigure.State = nextState;
                currentFigure.Body  = nextStateCurFig.Body;
            }
        }
Пример #12
0
        // Метод, отвечающий за поворот фигуры против часовой стрелке.
        public static void RotateLeft(ITetramino currentFigure, bool[,] buildingArea)
        {
            int nextState = currentFigure.State;                                    //Запоминаем номер текущего положения фигуры во временную переменную.

            if (currentFigure.State - 1 < 1)                                        //Делаем проверку на выход из массива положений фигуры.
            {
                nextState = currentFigure.CountState;                               //Изменяем номер текущего положения на -1 (выполняем поворот против часовой стрелки).
            }
            else
            {
                nextState--;                                                        //Изменяем номер текущего положения на -1 (выполняем поворот против часовой стрелки).
            }
            ITetramino nextStateCurFig = (ITetramino)currentFigure.Clone();         //Создаем копию текущей фигуры.

            nextStateCurFig.Body = currentFigure.FigureState[nextState];            //Приводим новую фигуру в соответствии с измененным номером положения (уже повернутая).

            if (RotateCheck(nextStateCurFig, buildingArea))                         //Проверяем не будет ли ошибок, если фигуру повернуть.
            {
                currentFigure.State = nextState;                                    //Если ошибок нет, то выполняем поворот для изначальной фигуры.
                currentFigure.Body  = nextStateCurFig.Body;                         //(записываем номер положения временной фигуры и приводим саму фигуру в соответствии с номером).
            }
        }
Пример #13
0
        // Метод, отвечающий за проверку возможности поворота фигура.
        public static bool RotateCheck(ITetramino nextCurFig, bool[,] buildingArea)
        {
            if (nextCurFig.CurrentRow + nextCurFig.Body.GetLength(0) > buildingArea.GetLength(0))           //Если повернутая фигура окажется ниже
            {                                                                                               //нижней границы поля игры, то возвращаем
                return(false);                                                                              //"ложь" (поворот делать не стоит).
            }
            else if (nextCurFig.CurrentCol + nextCurFig.Body.GetLength(1) > buildingArea.GetLength(1))      //Если повернутая фигура окажется правее
            {                                                                                               //правой границы поля игры, то возвращаем
                return(false);                                                                              //"ложь" (поворот делать не стоит).
            }

            for (int row = 0; row < nextCurFig.Body.GetLength(0); row++)                                //Если части повернутой фигуры оказались внутри
            {                                                                                           //построенных блоков, то также возвращаем "ложь".
                for (int col = 0; col < nextCurFig.Body.GetLength(1); col++)
                {
                    if (buildingArea[nextCurFig.CurrentRow + row, nextCurFig.CurrentCol + col] == true &
                        nextCurFig.Body[row, col] == true)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }