Exemple #1
0
        public Field(FormTetris formTetris)
        {
            form = formTetris;

            ClearField();

            cellStates = new CellStates[MyGraphics.COLUMNS_COUNT, MyGraphics.ROWS_COUNT];
            cellColor  = new FigureColors[MyGraphics.COLUMNS_COUNT, MyGraphics.ROWS_COUNT];

            neighborsList = new List <Figure.NeighboringCells>();
            fullRowsList  = new List <int>();

            GenerateFigureParameters();

            figure = Figure.CreateFigure(figureName);
            MyGraphics.DrawFigure(figure, form.splitContainer1.Panel2);

            GenerateFigureParameters();

            PrintFigureOnPlNextFigure();

            gameOver = false;
            score    = 0;
            form.LblCurrentScore.Text = "Очки: " + score;

            SetEvents();
            form.LblCurrentScore.Visible = true;

            form.timer1.Start();
        }
Exemple #2
0
 /// <summary>
 /// Поворот фигуры
 /// </summary>
 public void Turn()
 {
     MyGraphics.EraseFigure(figure, form.splitContainer1.Panel2);
     figure.Turn();
     MyGraphics.DrawCells(neighborsList, form.splitContainer1.Panel2);
     MyGraphics.DrawFigure(figure, form.splitContainer1.Panel2);
     neighborsList = figure.CheckNeighboringCells();
 }
Exemple #3
0
        /// <summary>
        /// Ход вправо
        /// </summary>
        public void MoveRight()
        {
            if (figure.CanMoveRight())
            {
                MyGraphics.EraseFigure(figure, form.splitContainer1.Panel2);
                figure.MoveRight();
                MyGraphics.DrawCells(neighborsList, form.splitContainer1.Panel2);
                MyGraphics.DrawFigure(figure, form.splitContainer1.Panel2);

                neighborsList = figure.CheckNeighboringCells();
            }
        }
Exemple #4
0
 /// <summary>
 /// Проверить, сможет ли созданная фигура падать
 /// </summary>
 private void CheckEndGame()
 {
     if (!figure.CanFall())
     {
         GameOver();
     }
     else
     {
         GenerateFigureParameters();
         PrintFigureOnPlNextFigure();
         MyGraphics.DrawFigure(figure, form.splitContainer1.Panel2);
     }
 }
Exemple #5
0
        /// <summary>
        /// Падение
        /// </summary>
        public void Fall()
        {
            if (!figure.CanFall())
            {
                FreezeFigure();

                int[] coordinatesForDel = CheckFilling().ToArray();

                if (coordinatesForDel.Length > 0)
                {
                    for (int i = 0; i < coordinatesForDel.Length; i++)
                    {
                        ChangeCoordinates(coordinatesForDel[i]);
                        IncreaseScore?.Invoke(Events.DeleteRows);
                    }

                    MyGraphics.ClearCells(form.splitContainer1.Panel2);
                    MyGraphics.DrawCells(form.splitContainer1.Panel2);
                    neighborsList.Clear();
                }
                else
                {
                    IncreaseScore?.Invoke(Events.Fall);
                }

                figure = Figure.CreateFigure(figureName);

                CheckEndGame();
            }
            else
            {
                MyGraphics.EraseFigure(figure, form.splitContainer1.Panel2);
                figure.Fall();
                MyGraphics.DrawCells(neighborsList, form.splitContainer1.Panel2);
                MyGraphics.DrawFigure(figure, form.splitContainer1.Panel2);

                neighborsList = figure.CheckNeighboringCells();
            }
        }
Exemple #6
0
        /// <summary>
        /// Отобразить следуюущую фигуру
        /// </summary>
        private void PrintFigureOnPlNextFigure()
        {
            var coordinates = Figure.CreateCoordinatesForPlNextFigure(figureName, out figureColor);

            MyGraphics.DrawFigureOnPlNextFigure(coordinates, figureColor, form.PlNextFigure);
        }
Exemple #7
0
 /// <summary>
 /// Обновить поле
 /// </summary>
 private void ClearField()
 {
     MyGraphics.ClearCells(form.splitContainer1.Panel2);
 }