Пример #1
0
        private void KeyDownHandler(object sender, PreviewKeyDownEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Z:
                currentPiece.Rotate(board, Direction.Left);
                break;

            case Keys.X:
                currentPiece.Rotate(board, Direction.Right);
                break;

            case Keys.Left:
                if (dasStatus != DASStatus.Unloaded)
                {
                    break;
                }
                dasStatus = DASStatus.Delay;
                currentPiece.Move(board, Direction.Left);
                lastMoveFrame = frameCounter;
                moveDirection = Direction.Left;
                break;

            case Keys.Right:
                if (dasStatus != DASStatus.Unloaded)
                {
                    break;
                }
                dasStatus = DASStatus.Delay;
                currentPiece.Move(board, Direction.Right);
                lastMoveFrame = frameCounter;
                moveDirection = Direction.Right;
                break;
            }
        }
Пример #2
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (!isGameOn)
            {
                return(false);
            }
            if (currentPiece == null)
            {
                return(false);
            }
            switch (keyData)
            {
            case Keys.Z:
                currentPiece.Rotate(board, Direction.Left);
                break;

            case Keys.X:
                currentPiece.Rotate(board, Direction.Right);
                break;

            case Keys.Left:
                if (dasStatus != DASStatus.Unloaded)
                {
                    break;
                }
                dasStatus = DASStatus.Delay;
                currentPiece.Move(board, Direction.Left);
                lastMoveFrame = frameCounter;
                moveDirection = Direction.Left;
                return(true);

            case Keys.Right:
                if (dasStatus != DASStatus.Unloaded)
                {
                    break;
                }
                dasStatus = DASStatus.Delay;
                currentPiece.Move(board, Direction.Right);
                lastMoveFrame = frameCounter;
                moveDirection = Direction.Right;
                return(true);

            case Keys.Down:
                dropRate = 2;
                return(true);
            }
            return(base.ProcessCmdKey(ref msg, keyData));
        }
Пример #3
0
        private void MakeMove()
        {
            if (!isGameOn)
            {
                return;
            }
            if (dasStatus == DASStatus.Unloaded)
            {
                return;
            }
            int delay = dasStatus == DASStatus.Delay ? Params.dasDelay : Params.dasNormalRate;

            if (frameCounter - lastMoveFrame == delay)
            {
                dasStatus = DASStatus.Loaded;
                currentPiece.Move(board, moveDirection);
                lastMoveFrame = frameCounter;
            }
        }
Пример #4
0
        private void KeyUpHandler(object sender, KeyEventArgs e)
        {
            if (!isGameOn)
            {
                return;
            }
            switch (e.KeyCode)
            {
            case Keys.Left:
                dasStatus = DASStatus.Unloaded;
                break;

            case Keys.Right:
                dasStatus = DASStatus.Unloaded;
                break;

            case Keys.Down:
                dropRate = Params.dropRate[level];
                break;
            }
        }
Пример #5
0
        private void Reset()
        {
            pictureBox1.BackColor = Params.backgroundColor;
            pictureBox1.Image     = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            pictureBox2.Image     = new Bitmap(pictureBox2.Width, pictureBox2.Height);

            graphics  = Graphics.FromImage(pictureBox1.Image);
            graphics2 = Graphics.FromImage(pictureBox2.Image);

            if (timer != null)
            {
                timer.Stop();
            }
            timer          = new Timer();
            timer.Interval = 1000 / Params.framesPerSecond;
            timer.Tick    += CalculateNextFrame;
            timer.Start();

            currentPiece = null;
            nextPiece    = null;

            board         = new Board();
            frameCounter  = 1;
            dasStatus     = DASStatus.Unloaded;
            lastMoveFrame = 0;


            showLineDisappearAnimation = false;
            animationStartFrame        = 0;
            completedLinesIndices      = null;
            columnToEraseIndicator     = 0;

            SetResultAndLabels();
            dropRate = Params.dropRate[level];
            Render();
        }