예제 #1
0
파일: Form1.cs 프로젝트: cloy123/Tetris-WF
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (Pause)
            {
                return;
            }

            switch (e.KeyCode)
            {
            case Keys.Left:
                FigureControl.Left(NowFigure, IfCellsFree);
                pictureBox1.Invalidate();
                break;

            case Keys.Right:
                FigureControl.Right(NowFigure, IfCellsFree);
                pictureBox1.Invalidate();
                break;

            case Keys.Up:
                FigureControl.Up(NowFigure, IfCellsFree);
                pictureBox1.Invalidate();
                break;

            case Keys.Down:
                FigureControl.Down(NowFigure, ref IfCellsFree);
                pictureBox1.Invalidate();
                break;
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: cloy123/Tetris-WF
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (Pause)
            {
                return;
            }

            if (!FigureControl.Down(NowFigure, ref IfCellsFree))
            {
                UpdateFigures();

                for (int y = PicBoxSizeClass.Border; y < PicBoxSizeClass.PicBoxSize.Height - PicBoxSizeClass.Border; y += (PicBoxSizeClass.RectSize + PicBoxSizeClass.MarginSize))
                {
                    List <Rect> NewRects = new List <Rect>();

                    bool b = false;//if the line contains empty cells

                    for (int x = PicBoxSizeClass.Border; x < PicBoxSizeClass.PicBoxSize.Width - PicBoxSizeClass.Border; x += (PicBoxSizeClass.RectSize + PicBoxSizeClass.MarginSize))
                    {
                        if (IfCellsFree[new Point(x, y)])
                        {
                            b = true;
                            break;
                        }
                    }

                    if (!b)
                    {
                        foreach (Rect rect in Rects)
                        {
                            if (rect.Point.Y < y)
                            {
                                rect.Point.Y += (PicBoxSizeClass.MarginSize + PicBoxSizeClass.RectSize);
                                NewRects.Add(rect);
                            }
                            else if (rect.Point.Y != y)
                            {
                                NewRects.Add(rect);
                            }
                        }
                        Rects.Clear();
                        Rects.AddRange(NewRects);

                        Dictionary <Point, bool> NewDict = new Dictionary <Point, bool>();

                        foreach (Point p in IfCellsFree.Keys)
                        {
                            NewDict.Add(p, true);
                        }
                        IfCellsFree = NewDict;
                        foreach (Rect rect in Rects)
                        {
                            IfCellsFree[rect.Point] = false;
                        }
                    }
                }
            }
            pictureBox1.Invalidate();
        }