Exemple #1
0
        public void DrawNext()
        {
            Bitmap   bitmap = new Bitmap(NextPanelSize.Width, NextPanelSize.Height);
            Graphics gi     = Graphics.FromImage(bitmap);

            gi.Clear(BackColor);
            NextFigure.Draw(gi, 2, 1);
            GraphicsNext.DrawImage(bitmap, new Point(0, 0));
        }
Exemple #2
0
 public GameTab(Game game, int difficultIndex)
     : base(game)
 {
     information = new Information(this);
     nextFigure = new NextFigure(this);
     gameField = new GameField(this);
     difficult = Difficulty.getDifficult(difficultIndex);
     information.difVariant = (Difficulty.Variants)difficultIndex;
 }
Exemple #3
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();
        }
Exemple #4
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();
        }