예제 #1
0
파일: Block.cs 프로젝트: onlyurei/lumines
        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);
            }
        }
예제 #2
0
        private void keyDown(object sender, KeyEventArgs e)
        {
            if (cmdStart.Enabled == false)
            {
                switch (e.KeyCode)
                {
                case Keys.Right:
                    if (paused)
                    {
                        return;
                    }
                    CurrentBlock.Right();
                    break;

                case Keys.Left:
                    if (paused)
                    {
                        return;
                    }
                    CurrentBlock.Left();
                    break;

                case Keys.Up:
                    if (paused)
                    {
                        return;
                    }
                    CurrentBlock.Rotate();
                    break;

                case Keys.Down:
                    if (paused)
                    {
                        return;
                    }
                    while (CurrentBlock.Down())
                    {
                        ;
                    }
                    if (CurrentBlock.Top() < 1)
                    {
                        tmrTime.Enabled       = false;
                        tmrBonusCheck.Enabled = false;
                        tmrGameClock.Enabled  = false;
                        tmrScanLine.Enabled   = false;
                        cmdStart.Enabled      = true;
                        lblGAMEOVER.Visible   = true;
                        stillProcessing       = false;
                        return;
                    }
                    //消去顶部第二行方块
                    for (int x = 0; x <= GameField.Width - 1; x++)
                    {
                        for (int y = 0; y <= 1; y++)
                        {
                            if (GameField.ArrGameField[x, y] != null)
                            {
                                GameField.ArrGameField[x, y].Hide(GameField.WinHandle);
                                GameField.ArrGameField[x, y] = null;
                            }
                        }
                    }
                    if (!GameField.DoAllDeletedCheck)
                    {
                        GameField.DoAllDeletedCheck = true;
                    }
                    //更换当前方块
                    CurrentBlock = new Block(new Point(GameField.SquareSize * 7 + 8, 1), NextBlock1.BlockType, NextBlock1.direction);
                    CurrentBlock.Show(picBackGround.Handle);
                    //创建下一方块
                    NextBlock1.Hide(picNextBlock1.Handle);
                    NextBlock1 = new Block(new Point(0, 0), NextBlock2.BlockType, NextBlock2.direction);
                    NextBlock1.Show(picNextBlock1.Handle);
                    NextBlock2 = new Block(new Point(0, 0), NextBlock3.BlockType, NextBlock3.direction);
                    NextBlock2.Show(picNextBlock2.Handle);
                    NextBlock3 = new Block(new Point(0, 0), Block.BlockTypes.Undefined, 0);
                    NextBlock3.Show(picNextBlock3.Handle);
                    //使方块在顶部暂留一会儿
                    tmrGameClock.Enabled = false;
                    tmrHold.Enabled      = true;
                    blockHold            = true;
                    break;

                case Keys.Space:
                    tmrScanLine.Enabled = !tmrScanLine.Enabled;
                    tmrTime.Enabled     = !tmrTime.Enabled;
                    lblPAUSED.Visible   = !lblPAUSED.Visible;
                    if (tmrScanLine.Enabled)
                    {
                        paused    = false;
                        this.Text = "LUMINES";
                        picBackGround.Invalidate();
                        picNextBlock1.Invalidate();
                        picNextBlock2.Invalidate();
                        picNextBlock3.Invalidate();
                        Application.DoEvents();
                        GameField.Redraw();
                        GameField.CheckBlocks(0, GameField.Width - 1);
                        CurrentBlock.Show(GameField.WinHandle);
                        if (NextBlock1 != null)
                        {
                            NextBlock1.Show(picNextBlock1.Handle);
                        }
                        if (NextBlock2 != null)
                        {
                            NextBlock2.Show(picNextBlock2.Handle);
                        }
                        if (NextBlock3 != null)
                        {
                            NextBlock3.Show(picNextBlock3.Handle);
                        }
                        if (blockHold == true)
                        {
                            tmrGameClock.Enabled = false;
                            tmrHold.Enabled      = true;
                        }
                        else
                        {
                            tmrGameClock.Enabled = true;
                            tmrHold.Enabled      = false;
                        }
                    }
                    else
                    {
                        paused               = true;
                        this.Text            = "LUMINES (Paused), Press 'SPACE' to Continue";
                        tmrGameClock.Enabled = false;
                        tmrHold.Enabled      = false;
                    }
                    break;

                case Keys.R:
                    tmrGameClock.Enabled = false;
                    tmrScanLine.Enabled  = false;
                    tmrHold.Enabled      = false;
                    tmrTime.Enabled      = false;
                    if (MessageBox.Show("RESTART?", "RESTART CONFIRM", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        //清屏并结束
                        GameField.Reset();
                        picBackGround.Invalidate();
                        picNextBlock1.Invalidate();
                        picNextBlock2.Invalidate();
                        picNextBlock3.Invalidate();
                        Application.DoEvents();
                        cmdStart.Enabled      = true;
                        this.Text             = "LUMINES";
                        lblSTART.Visible      = true;
                        lblLUMINES.Visible    = true;
                        lblPAUSED.Visible     = false;
                        stillProcessing       = false;
                        stillScanning         = false;
                        lblScoreValue.Text    = "0";
                        lblDeleted.Text       = "0";
                        lblLevelValue.Text    = "1";
                        lblTime.Text          = "0:00";
                        BonusInfo             = "";
                        tmrBonusCheck.Enabled = false;
                        paused = false;
                    }
                    else     //返回游戏
                    {
                        paused            = false;
                        this.Text         = "LUMINES";
                        lblPAUSED.Visible = false;
                        picBackGround.Invalidate();
                        picNextBlock1.Invalidate();
                        picNextBlock2.Invalidate();
                        picNextBlock3.Invalidate();
                        Application.DoEvents();
                        GameField.Redraw();
                        GameField.CheckBlocks(0, GameField.Width - 1);
                        CurrentBlock.Show(GameField.WinHandle);
                        if (NextBlock1 != null)
                        {
                            NextBlock1.Show(picNextBlock1.Handle);
                        }
                        if (NextBlock2 != null)
                        {
                            NextBlock2.Show(picNextBlock2.Handle);
                        }
                        if (NextBlock3 != null)
                        {
                            NextBlock3.Show(picNextBlock3.Handle);
                        }
                        tmrScanLine.Enabled = true;
                        tmrTime.Enabled     = true;
                        if (blockHold == true)
                        {
                            tmrGameClock.Enabled = false;
                            tmrHold.Enabled      = true;
                        }
                        else
                        {
                            tmrGameClock.Enabled = true;
                            tmrHold.Enabled      = false;
                        }
                    }
                    break;

                default: break;
                }
                Invalidate();
            }
        }
예제 #3
0
        private void tmrScanLine_Tick(object sender, EventArgs e)
        {
            if (stillScanning)
            {
                return;
            }
            stillScanning = true;
            int x  = scanLineActivePos / (GameField.SquareSize + 1);
            int dx = scanLineActivePos % (GameField.SquareSize + 1);

            if (x == 0)
            {
                if (GameField.DelCol[0])
                {
                    startX = 0;
                    if (dx == 0)
                    {
                        GameField.HideBlocks(0, 0);
                    }
                    else if (dx == GameField.SquareSize)
                    {
                        if (!GameField.DelCol[1])
                        {
                            GameField.DeleteBlocks(0, 0);
                            GameField.DoSetDelCol          = true;
                            GameField.DeletedBlocksOnePass = 0;
                        }
                        else
                        {
                            GameField.DoSetDelCol = false;
                        }
                    }
                }
            }
            else if (x > 0 && x < GameField.Width - 1)
            {
                if (!GameField.DelCol[x - 1] && GameField.DelCol[x])
                {
                    startX = x;
                    if (dx == 0)
                    {
                        GameField.HideBlocks(x, x);
                    }
                    else if (dx == GameField.SquareSize)
                    {
                        if (!GameField.DelCol[x + 1])
                        {
                            GameField.DeleteBlocks(x, x);
                            GameField.DoSetDelCol          = true;
                            GameField.DeletedBlocksOnePass = 0;
                        }
                        else
                        {
                            GameField.DoSetDelCol = false;
                        }
                    }
                }
                else if (GameField.DelCol[x] && !GameField.DelCol[x + 1])
                {
                    if (dx == 0)
                    {
                        GameField.HideBlocks(x, x);
                    }
                    else if (dx == GameField.SquareSize)
                    {
                        GameField.DeleteBlocks(startX, x);
                        GameField.DoSetDelCol          = true;
                        GameField.DeletedBlocksOnePass = 0;
                    }
                }
                else if (GameField.DelCol[x])
                {
                    if (dx == 0)
                    {
                        GameField.HideBlocks(x, x);
                        GameField.DoSetDelCol = false;
                    }
                }
            }
            else if (x == GameField.Width - 1)
            {
                if (dx == 0)
                {
                    if (GameField.DelCol[x])
                    {
                        GameField.HideBlocks(x, x);
                    }
                    if (GameField.DelCol[x - 1])
                    {
                        startX = x - 1;
                    }
                    else
                    {
                        startX = x;
                    }
                }
                else if (dx == GameField.SquareSize)
                {
                    if (GameField.DelCol[x])
                    {
                        GameField.DeleteBlocks(startX, x);
                        GameField.DeletedBlocksOnePass = 0;
                    }
                    GameField.DoSetDelCol = true;
                    if (GameField.DeletedBlocks < 8)
                    {
                        GameField.Score += GameField.DeletedBlocks * 40;
                    }
                    else
                    {
                        GameField.Score += GameField.DeletedBlocks * 40 * GameField.DeletedBlocks;
                    }
                    lblScoreValue.Text = GameField.Score.ToString();
                    lblDeleted.Text    = GameField.DeletedBlocksTotal.ToString();
                    if (GameField.DeletedBlocks < 6)
                    {
                    }
                    else if (GameField.DeletedBlocks <= 8)
                    {
                        BonusInfo = "GOOD!";
                    }
                    else if (GameField.DeletedBlocks <= 12)
                    {
                        BonusInfo = "EXCELLENT!";
                    }
                    else if (GameField.DeletedBlocks <= 16)
                    {
                        BonusInfo = "AWESOME!";
                    }
                    else if (GameField.DeletedBlocks <= 20)
                    {
                        BonusInfo = "SUPER AWESOME!!";
                    }
                    else if (GameField.DeletedBlocks <= 24)
                    {
                        BonusInfo = "CRAZY!!";
                    }
                    else if (GameField.DeletedBlocks <= 28)
                    {
                        BonusInfo = "IMPOSSIBLE...";
                    }
                    else
                    {
                        BonusInfo = "THAT'S CHEATING!!!";
                    }
                    if (highScore < GameField.Score)
                    {
                        highScore         = GameField.Score;
                        lblHighScore.Text = highScore.ToString();
                        //保存最高分数
                        try
                        {
                            Properties.Settings.Default.HighScore = highScore.ToString();
                            Properties.Settings.Default.Save();
                        }
                        catch (Exception E)
                        {
                        }
                    }
                    //升级操作
                    if (GameField.Score >= GameField.ScoreLevel)
                    {
                        GameField.ScoreLevel += 10000;
                        GameField.Level++;
                        lblLevelValue.Text = GameField.Level.ToString();
                        //随机改变方块下落速度和扫描线移动速度
                        Random random = new Random();
                        tmrGameClock.Interval = (int)(random.NextDouble() * 300 + 240);
                        tmrScanLine.Interval  = (int)(random.NextDouble() * 15 + 10);
                        //改变方块圆角大小
                        GameField.SquareRoundCorner = random.Next(2) + 1;
                        //更换扫描线颜色
                        int oldScanLineColor = GameField.ScanLineColorIndex;
                        while (GameField.ScanLineColorIndex == oldScanLineColor)
                        {
                            GameField.ScanLineColorIndex = random.Next(5);
                        }
                        //更换方块颜色
                        int oldColor1 = Block.Color1;
                        int oldColor2 = Block.Color2;
                        //保证方块的两种颜色跟变换前不一样,并且组成方块的两种颜色不相同
                        while (Block.Color1 == oldColor1 || Block.Color2 == oldColor2 || Block.Color1 == oldColor2 || Block.Color2 == oldColor1 ||
                               (Block.Color2 == Block.Color1) ||
                               (Block.backColors[Block.Color1] == Color.LimeGreen && Block.backColors[Block.Color2] == Color.Red) ||
                               (Block.backColors[Block.Color2] == Color.LimeGreen && Block.backColors[Block.Color1] == Color.Red) ||
                               (Block.backColors[Block.Color1] == Color.Red && Block.backColors[Block.Color2] == Color.DeepPink) ||
                               (Block.backColors[Block.Color2] == Color.Red && Block.backColors[Block.Color1] == Color.DeepPink) ||
                               (Block.backColors[Block.Color1] == Color.LimeGreen && Block.backColors[Block.Color2] == Color.DeepPink) ||
                               (Block.backColors[Block.Color2] == Color.LimeGreen && Block.backColors[Block.Color1] == Color.DeepPink))
                        {
                            Block.Color1 = random.Next(9) + 1;
                            Block.Color2 = random.Next(9) + 1;
                        }
                        //更换当前下落方块和三个预告方块的颜色
                        if (CurrentBlock.squareNE.ForeColor == Block.foreColors[oldColor1])
                        {
                            CurrentBlock.squareNE.ForeColor = Block.foreColors[Block.Color1];
                            CurrentBlock.squareNE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            CurrentBlock.squareNE.ForeColor = Block.foreColors[Block.Color2];
                            CurrentBlock.squareNE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (CurrentBlock.squareNW.ForeColor == Block.foreColors[oldColor1])
                        {
                            CurrentBlock.squareNW.ForeColor = Block.foreColors[Block.Color1];
                            CurrentBlock.squareNW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            CurrentBlock.squareNW.ForeColor = Block.foreColors[Block.Color2];
                            CurrentBlock.squareNW.BackColor = Block.backColors[Block.Color2];
                        }
                        if (CurrentBlock.squareSE.ForeColor == Block.foreColors[oldColor1])
                        {
                            CurrentBlock.squareSE.ForeColor = Block.foreColors[Block.Color1];
                            CurrentBlock.squareSE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            CurrentBlock.squareSE.ForeColor = Block.foreColors[Block.Color2];
                            CurrentBlock.squareSE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (CurrentBlock.squareSW.ForeColor == Block.foreColors[oldColor1])
                        {
                            CurrentBlock.squareSW.ForeColor = Block.foreColors[Block.Color1];
                            CurrentBlock.squareSW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            CurrentBlock.squareSW.ForeColor = Block.foreColors[Block.Color2];
                            CurrentBlock.squareSW.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock1.squareNE.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock1.squareNE.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock1.squareNE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock1.squareNE.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock1.squareNE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock1.squareNW.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock1.squareNW.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock1.squareNW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock1.squareNW.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock1.squareNW.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock1.squareSE.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock1.squareSE.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock1.squareSE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock1.squareSE.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock1.squareSE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock1.squareSW.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock1.squareSW.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock1.squareSW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock1.squareSW.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock1.squareSW.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock2.squareNE.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock2.squareNE.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock2.squareNE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock2.squareNE.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock2.squareNE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock2.squareNW.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock2.squareNW.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock2.squareNW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock2.squareNW.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock2.squareNW.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock2.squareSE.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock2.squareSE.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock2.squareSE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock2.squareSE.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock2.squareSE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock2.squareSW.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock2.squareSW.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock2.squareSW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock2.squareSW.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock2.squareSW.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock3.squareNE.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock3.squareNE.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock3.squareNE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock3.squareNE.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock3.squareNE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock3.squareNW.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock3.squareNW.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock3.squareNW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock3.squareNW.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock3.squareNW.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock3.squareSE.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock3.squareSE.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock3.squareSE.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock3.squareSE.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock3.squareSE.BackColor = Block.backColors[Block.Color2];
                        }
                        if (NextBlock3.squareSW.ForeColor == Block.foreColors[oldColor1])
                        {
                            NextBlock3.squareSW.ForeColor = Block.foreColors[Block.Color1];
                            NextBlock3.squareSW.BackColor = Block.backColors[Block.Color1];
                        }
                        else
                        {
                            NextBlock3.squareSW.ForeColor = Block.foreColors[Block.Color2];
                            NextBlock3.squareSW.BackColor = Block.backColors[Block.Color2];
                        }
                        //更换已落底方块的颜色
                        for (int i = 0; i <= GameField.Width - 1; i++)
                        {
                            for (int j = 0; j <= GameField.Height - 1; j++)
                            {
                                if (GameField.ArrGameField[i, j] != null)
                                {
                                    if (GameField.ArrGameField[i, j].ForeColor == Block.foreColors[oldColor1])
                                    {
                                        GameField.ArrGameField[i, j].ForeColor = Block.foreColors[Block.Color1];
                                        GameField.ArrGameField[i, j].BackColor = Block.backColors[Block.Color1];
                                    }
                                    else
                                    {
                                        GameField.ArrGameField[i, j].ForeColor = Block.foreColors[Block.Color2];
                                        GameField.ArrGameField[i, j].BackColor = Block.backColors[Block.Color2];
                                    }
                                }
                            }
                        }
                        //重绘窗口使方块颜色更新
                        picBackGround.Invalidate();
                        picNextBlock1.Invalidate();
                        picNextBlock2.Invalidate();
                        picNextBlock3.Invalidate();
                        Application.DoEvents();
                        GameField.Redraw();
                        GameField.CheckBlocks(0, GameField.Width - 1);
                        if (CurrentBlock != null)
                        {
                            CurrentBlock.Show(GameField.WinHandle);
                        }
                        if (NextBlock1 != null)
                        {
                            NextBlock1.Show(picNextBlock1.Handle);
                        }
                        if (NextBlock2 != null)
                        {
                            NextBlock2.Show(picNextBlock2.Handle);
                        }
                        if (NextBlock3 != null)
                        {
                            NextBlock3.Show(picNextBlock3.Handle);
                        }
                    }
                }
            }

            ScanLine scanLine = new ScanLine(GameField.ScanLineColorIndex);

            scanLine.HideTop(scanLineActivePos - 1);
            scanLine.ShowTop(scanLineActivePos);

            if (scanLineActivePos == 0)
            {
                GameField.DeletedBlocks = 0;
                ScanLine.ScanLineGraphic.DrawLine(new Pen(GameField.GridColor, 1),
                                                  new Point(this.picBackGround.Width, 34), new Point(this.picBackGround.Width, this.picBackGround.Height));
                Rectangle rectangle = new Rectangle(new Point(this.picBackGround.Width - 28, 19), new Size(28, 14));
                ScanLine.ScanLineGraphic.DrawRectangle(new Pen(GameField.BackColor, 1), rectangle);
                ScanLine.ScanLineGraphic.FillRectangle(new SolidBrush(GameField.BackColor), rectangle);
            }
            if (dx == 0)
            {
                if (x >= 2 && x <= GameField.Width)
                {
                    bool doSth = true;
                    for (int c = 2; c <= GameField.Height - 1; c++)
                    {
                        if (GameField.ArrGameField[x - 1, c] != null)
                        {
                            if (GameField.ArrGameField[x - 1, c].Delete)
                            {
                                doSth = false;
                                break;
                            }
                        }
                    }
                    if (doSth)
                    {
                        for (int i = 0; i <= x - 2; i++)
                        {
                            if (GameField.HideCol[i])
                            {
                                GameField.DeleteBlocks(i, i);
                            }
                        }
                    }
                }
                for (int y = 2; y <= GameField.Height - 1; y++)
                {
                    if (x >= 1)
                    {
                        if (GameField.ArrGameField[x - 1, y] == null)
                        {
                            ScanLine.ScanLineGraphic.DrawLine(new Pen(new SolidBrush(this.picBackGround.BackColor), 1),
                                                              new Point(scanLineActivePos - 1, y * (GameField.SquareSize + 1) + 1), new Point(scanLineActivePos - 1, y * (GameField.SquareSize + 1) + 1 + GameField.SquareSize));
                        }
                    }
                }
                for (int y = 34; y <= this.picBackGround.Height; y += 17)
                {
                    ScanLine.ScanLineGraphic.DrawLine(new Pen(new SolidBrush(GameField.GridColor), 1),
                                                      new Point(scanLineActivePos - 1, y), new Point(scanLineActivePos, y));
                }
            }
            else if (dx == 1)
            {
                ScanLine.ScanLineGraphic.DrawLine(new Pen(new SolidBrush(GameField.GridColor), 1),
                                                  new Point(scanLineActivePos - 1, 34), new Point(scanLineActivePos - 1, this.picBackGround.Height));
            }
            else
            {
                for (int y = 2; y <= GameField.Height - 1; y++)
                {
                    if (x <= GameField.Width - 1)
                    {
                        if (GameField.ArrGameField[x, y] == null)
                        {
                            ScanLine.ScanLineGraphic.DrawLine(new Pen(new SolidBrush(this.picBackGround.BackColor), 1),
                                                              new Point(scanLineActivePos - 1, y * (GameField.SquareSize + 1) + 1), new Point(scanLineActivePos - 1, y * (GameField.SquareSize + 1) + 1 + GameField.SquareSize));
                        }
                    }
                }
                for (int y = 34; y <= this.picBackGround.Height; y += 17)
                {
                    ScanLine.ScanLineGraphic.DrawLine(new Pen(new SolidBrush(GameField.GridColor), 1),
                                                      new Point(scanLineActivePos - 1, y), new Point(scanLineActivePos, y));
                }
            }

            for (int y = 2; y <= GameField.Height - 1; y++)
            {
                if (x <= GameField.Width - 1)
                {
                    if (GameField.ArrGameField[x, y] == null)
                    {
                        scanLine.Show(scanLineActivePos, y * (GameField.SquareSize + 1), y * (GameField.SquareSize + 1) + GameField.SquareSize);
                    }
                }
            }

            if (CurrentBlock != null)
            {
                CurrentBlock.Show(GameField.WinHandle);
            }

            if (scanLineActivePos == this.picBackGround.Width)
            {
                for (int i = 0; i <= GameField.Width - 1; i++)
                {
                    if (GameField.HideCol[i])
                    {
                        GameField.DeleteBlocks(i, i);
                    }
                }
                scanLineActivePos = 0;
            }
            else
            {
                scanLineActivePos++;
            }

            if (NextBlock1 != null)
            {
                NextBlock1.Show(picNextBlock1.Handle);
            }
            if (NextBlock2 != null)
            {
                NextBlock2.Show(picNextBlock2.Handle);
            }
            if (NextBlock3 != null)
            {
                NextBlock3.Show(picNextBlock3.Handle);
            }
            stillScanning = false;
        }
예제 #4
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();
        }