Exemple #1
0
        private void gameReset()
        {
            //参数重置
            GameField.Score                = 0;
            GameField.ScoreLevel           = 10000;
            GameField.DoBonus              = false;
            GameField.DoAllDeletedCheck    = false;
            GameField.DoUniColorCheck      = false;
            GameField.Level                = 1;
            GameField.DeletedBlocks        = 0;
            GameField.DeletedBlocksOnePass = 0;
            GameField.DeletedBlocksTotal   = 0;
            stillProcessing                = false;
            stillScanning         = false;
            elapsedSeconds        = 0;
            GameField.DoSetDelCol = true;
            blockHold             = true;
            scanLineActivePos     = 0;

            //控件重置
            tmrGameClock.Enabled           = false;
            tmrHold.Enabled                = true;
            tmrScanLine.Enabled            = true;
            tmrTime.Enabled                = true;
            tmrBonusCheck.Enabled          = true;
            cmdStart.Enabled               = false;
            lblScoreValue.Text             = "0";
            lblDeleted.Text                = "0";
            lblLevelValue.Text             = "1";
            lblGAMEOVER.Visible            = false;
            lblSTART.Visible               = false;
            lblLUMINES.Visible             = false;
            lblPAUSED.Visible              = false;
            lblHighScoreLoadFailed.Visible = false;
            lblBonus.Text = "";
            lblTime.Text  = "0:00";

            //清屏并重置
            GameField.Reset();
            picBackGround.Invalidate();
            picNextBlock1.Invalidate();
            picNextBlock2.Invalidate();
            picNextBlock3.Invalidate();
            Application.DoEvents();

            //重置方块下落速度和扫描线移动速度
            tmrGameClock.Interval = 480;
            tmrScanLine.Interval  = 14;
        }
Exemple #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();
            }
        }