Exemple #1
0
        public bool Down()
        {
            //没有方块被挡住
            if (GameField.IsEmpty((squareSW.Location.X - 1) / (squareSize + 1), (squareSW.Location.Y - 1) / (squareSize + 1) + 1) &&
                GameField.IsEmpty((squareSE.Location.X - 1) / (squareSize + 1), (squareSE.Location.Y - 1) / (squareSize + 1) + 1))
            {
                Hide(GameField.WinHandle);
                squareSW.Location = new Point(squareSW.Location.X, squareSW.Location.Y + squareSize + 1);
                squareNW.Location = new Point(squareNW.Location.X, squareNW.Location.Y + squareSize + 1);
                squareSE.Location = new Point(squareSE.Location.X, squareSE.Location.Y + squareSize + 1);
                squareNE.Location = new Point(squareNE.Location.X, squareNE.Location.Y + squareSize + 1);
                Show(GameField.WinHandle);
                return(true);
            }

            //右半边方块被挡住
            else if (GameField.IsEmpty((squareSW.Location.X - 1) / (squareSize + 1), (squareSW.Location.Y - 1) / (squareSize + 1) + 1) &&
                     !GameField.IsEmpty((squareSE.Location.X - 1) / (squareSize + 1), (squareSE.Location.Y - 1) / (squareSize + 1) + 1))
            {
                GameField.StopSquare(squareSE, (squareSE.Location.X - 1) / (squareSize + 1), (squareSE.Location.Y - 1) / (squareSize + 1));
                GameField.StopSquare(squareNE, (squareNE.Location.X - 1) / (squareSize + 1), (squareNE.Location.Y - 1) / (squareSize + 1));
                //让左半边方块落地
                while (GameField.IsEmpty((squareSW.Location.X - 1) / (squareSize + 1), (squareSW.Location.Y - 1) / (squareSize + 1) + 1))
                {
                    squareSW.Hide(GameField.WinHandle);
                    squareNW.Hide(GameField.WinHandle);
                    squareSW.Location = new Point(squareSW.Location.X, squareSW.Location.Y + squareSize + 1);
                    squareNW.Location = new Point(squareNW.Location.X, squareNW.Location.Y + squareSize + 1);
                    squareSW.Show(GameField.WinHandle);
                    squareNW.Show(GameField.WinHandle);
                }
                GameField.StopSquare(squareSW, (squareSW.Location.X - 1) / (squareSize + 1), (squareSW.Location.Y - 1) / (squareSize + 1));
                GameField.StopSquare(squareNW, (squareNW.Location.X - 1) / (squareSize + 1), (squareNW.Location.Y - 1) / (squareSize + 1));
                GameField.CheckBlocks(0, GameField.Width - 1);
                if (GameField.DoSetDelCol)
                {
                    GameField.SetDelCol();
                }
                GameField.DoAllDeletedCheck = true;
                GameField.DoUniColorCheck   = true;
                return(false);
            }

            //左半边方块被挡住
            else if (!GameField.IsEmpty((squareSW.Location.X - 1) / (squareSize + 1), (squareSW.Location.Y - 1) / (squareSize + 1) + 1) &&
                     GameField.IsEmpty((squareSE.Location.X - 1) / (squareSize + 1), (squareSE.Location.Y - 1) / (squareSize + 1) + 1))
            {
                GameField.StopSquare(squareSW, (squareSW.Location.X - 1) / (squareSize + 1), (squareSW.Location.Y - 1) / (squareSize + 1));
                GameField.StopSquare(squareNW, (squareNW.Location.X - 1) / (squareSize + 1), (squareNW.Location.Y - 1) / (squareSize + 1));
                //让右半边方块落地
                while (GameField.IsEmpty((squareSE.Location.X - 1) / (squareSize + 1), (squareSE.Location.Y - 1) / (squareSize + 1) + 1))
                {
                    squareSE.Hide(GameField.WinHandle);
                    squareNE.Hide(GameField.WinHandle);
                    squareSE.Location = new Point(squareSE.Location.X, squareSE.Location.Y + squareSize + 1);
                    squareNE.Location = new Point(squareNE.Location.X, squareNE.Location.Y + squareSize + 1);
                    squareSE.Show(GameField.WinHandle);
                    squareNE.Show(GameField.WinHandle);
                }
                GameField.StopSquare(squareSE, (squareSE.Location.X - 1) / (squareSize + 1), (squareSE.Location.Y - 1) / (squareSize + 1));
                GameField.StopSquare(squareNE, (squareNE.Location.X - 1) / (squareSize + 1), (squareNE.Location.Y - 1) / (squareSize + 1));
                GameField.CheckBlocks(0, GameField.Width - 1);
                if (GameField.DoSetDelCol)
                {
                    GameField.SetDelCol();
                }
                GameField.DoAllDeletedCheck = true;
                GameField.DoUniColorCheck   = true;
                return(false);
            }

            //整个方块被挡住
            else
            {
                GameField.StopSquare(squareSW, (squareSW.Location.X - 1) / (squareSize + 1), (squareSW.Location.Y - 1) / (squareSize + 1));
                GameField.StopSquare(squareNW, (squareNW.Location.X - 1) / (squareSize + 1), (squareNW.Location.Y - 1) / (squareSize + 1));
                GameField.StopSquare(squareSE, (squareSE.Location.X - 1) / (squareSize + 1), (squareSE.Location.Y - 1) / (squareSize + 1));
                GameField.StopSquare(squareNE, (squareNE.Location.X - 1) / (squareSize + 1), (squareNE.Location.Y - 1) / (squareSize + 1));
                GameField.CheckBlocks(0, GameField.Width - 1);
                if (GameField.DoSetDelCol)
                {
                    GameField.SetDelCol();
                }
                GameField.DoAllDeletedCheck = true;
                GameField.DoUniColorCheck   = true;
                return(false);
            }
        }
Exemple #2
0
        public static void DeleteBlocks(int x1, int x2)
        {
            int y;
            Pen pen = new Pen(GameField.GridColor, 1);

            for (int x = x1; x <= x2; x++)
            {
                if (x >= 0 && x <= Width - 1)
                {
                    y = Height - 1;
                    while (y > 2)
                    {
                        if (ArrGameField[x, y] == null)
                        {
                            y = 0;
                        }
                        else
                        if (ArrGameField[x, y].Delete == true)
                        {
                            //ArrGameField[x, y].Delete = false;
                            ArrGameField[x, y].DeleteHide(WinHandle);
                            if (ArrGameField[x, y].Counted)
                            {
                                DeletedBlocksTotal++;
                                DeletedBlocks++;
                                ArrGameField[x, y].Counted  = false;
                                ArrGameField[x, y].CountNum = 0;
                            }
                            for (int i = y; ArrGameField[x, i] != null && i >= 2; i--)
                            {
                                if (i >= 2)
                                {
                                    if (ArrGameField[x, i - 1] != null)
                                    {
                                        ArrGameField[x, i - 1].size = new Size(SquareSize, SquareSize);
                                        ArrGameField[x, i]          = ArrGameField[x, i - 1];
                                        ArrGameField[x, i - 1].DeleteHide(WinHandle);
                                        for (int i1 = i - 1; i1 <= i + 1; i1++)
                                        {
                                            if (i1 >= 2 && i1 <= Height)
                                            {
                                                ScanLine.ScanLineGraphic.DrawLine(pen, new Point(0, (SquareSize + 1) * i1),
                                                                                  new Point((SquareSize + 1) * Width, (SquareSize + 1) * i1));
                                            }
                                        }
                                    }
                                    else
                                    {
                                        ArrGameField[x, i].size = new Size(SquareSize, SquareSize);
                                        ArrGameField[x, i].DeleteHide(WinHandle);
                                        ArrGameField[x, i] = null;
                                        for (int i1 = i - 1; i1 <= i + 1; i1++)
                                        {
                                            if (i1 >= 2 && i1 <= Height)
                                            {
                                                ScanLine.ScanLineGraphic.DrawLine(pen, new Point(0, (SquareSize + 1) * i1),
                                                                                  new Point((SquareSize + 1) * Width, (SquareSize + 1) * i1));
                                            }
                                        }
                                    }
                                    //更新方块位置
                                    if (ArrGameField[x, i] != null)
                                    {
                                        ArrGameField[x, i].Location = new Point(ArrGameField[x, i].Location.X,
                                                                                ArrGameField[x, i].Location.Y + SquareSize + 1);
                                        ArrGameField[x, i].DrawGridFrame(WinHandle);
                                        ArrGameField[x, i].Show(WinHandle);
                                    }
                                }
                                else
                                {
                                    ArrGameField[x, i].size = new Size(SquareSize, SquareSize);
                                    ArrGameField[x, i].DeleteHide(WinHandle);
                                    ArrGameField[x, i] = null;
                                }
                            }
                        }
                        else
                        {
                            ArrGameField[x, y].DrawGridFrame(WinHandle);
                            ArrGameField[x, y].Show(WinHandle);
                            y--;
                        }
                    }
                }
                ScanLine.ScanLineGraphic.DrawLine(pen, new Point((SquareSize + 1) * x, 34),
                                                  new Point((SquareSize + 1) * x, (GameField.SquareSize + 1) * GameField.Width));
                HideCol[x] = false;
            }
            ScanLine.ScanLineGraphic.DrawLine(pen, new Point((SquareSize + 1) * (x2 + 1), 34),
                                              new Point((SquareSize + 1) * (x2 + 1), (GameField.SquareSize + 1) * GameField.Width));

            CheckBlocks(0, Width - 1);
            GameField.SetDelCol();
        }