Esempio n. 1
0
 //новая игра
 private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
 {
     timer.Stop();
     labelPause.Text    = @"PAUSE";
     labelPause.Visible = false;
     enter = true;
     //очищаем поле
     InitializeField();
     labelLevel.Text = @"Level: 1";
     labelLines.Text = @"Lines: 0";
     lines           = 0;
     figure          = nextFigure.GetNext(this);
     pictureBox1.Invalidate();
     //таймер запускающий игру
     timer.Start();
     PictureNextFigure.Invalidate();
 }
Esempio n. 2
0
        //конструктор
        public Form1()
        {
            InitializeComponent();

            nextFigure = new NextFigure(this);

            //инициализация таймера
            timer = new Timer {
                Interval = speed
            };
            timer.Tick += (sender, args) =>
            {
                if (figure.Down())
                {
                    ;
                }
                else
                {
                    HorizontalRow();
                    GameOver();
                    figure = nextFigure.GetNext(this);
                }
                pictureBox1.Invalidate();
                PictureNextFigure.Invalidate();
            };

            //инициализация цвета отрисовки подквадрата
            myPen = new Pen(Color.Black)
            {
                LineJoin = LineJoin.Miter,
                Width    = 2.0F
            };

            //отрисовка стакана и сетки
            pictureBox1.Image = (Image) new Bitmap(pictureBox1.Width, pictureBox1.Height);
            var g = Graphics.FromImage(pictureBox1.Image);
            var p = new Pen(Color.DarkSlateGray);

            for (var i = 0; i < 10; i++)
            {
                g.DrawLine(p, pictureBox1.Width / 10 * (i + 1), 0, pictureBox1.Width / 10 * (i + 1), pictureBox1.Height);
            }
            for (var i = 0; i < 20; i++)
            {
                g.DrawLine(p, 0, pictureBox1.Height / 20 * (i + 1), pictureBox1.Width, pictureBox1.Height / 20 * (i + 1));
            }

            //красная линия
            g.DrawLine(Pens.Red, 0, pictureBox1.Height / 20 * 3, pictureBox1.Width, pictureBox1.Height / 20 * 3);

            //инициализация массива/поля
            InitializeField();

            //текущий уровень сложности
            labelLevel.Text = $"Level: {level}";

            //инициализация массива координат следущей фигуры
            for (var i = 0; i < 3; i++)
            {
                for (var j = 0; j < 4; j++)
                {
                    smallField[i, j] = new Component((j * width) + 1, (i * width) + 1, Brushes.Black);
                }
            }

            //pictureBox на котором будет отображаться следущая фигура
            PictureNextFigure = new PictureBox
            {
                Location  = new Point(324, 91),
                Size      = new Size(101, 76),
                BackColor = Color.Black
            };

            //добавляем контрол к форме
            this.Controls.Add(PictureNextFigure);

            //обработчик перерисовки поля
            PictureNextFigure.Paint += (s, e) =>
            {
                for (var i = 0; i < 3; i++)
                {
                    for (var j = 0; j < 4; j++)
                    {
                        //если в текущей клетке стоит фигура рисуем квадрат
                        if (smallField[i, j].brush != Brushes.Black)
                        {
                            e.Graphics.FillRectangle(smallField[i, j].brush
                                                     , smallField[i, j].x, smallField[i, j].y, width - 1, width - 1);
                            //и подквадрат
                            e.Graphics.DrawRectangle(myPen, smallField[i, j].x + 3, smallField[i, j].y + 3,
                                                     width - 7, width - 7);
                        }
                    }
                }
            };

            labelPause.Text    = @"TETRIS";
            labelPause.Visible = true;
            soundControl.playMain();
        }