Ejemplo n.º 1
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            int   dX       = 0;
            int   dY       = 0;
            bool  rotate   = false;
            Piece tmpPiece = null;

            switch (e.KeyCode)
            {
            case Keys.Left:
                dX = -1;
                break;

            case Keys.Right:
                dX = 1;
                break;

            case Keys.Up:
                rotate = true;
                break;

            case Keys.Down:
                dY = 1;
                break;

            case Keys.Space:
                if (!_isRunning)
                {
                    return;
                }

                while (_currPiece != null && !_map.CheckCollision(tmpPiece = _currPiece.Move(0, 1)))
                {
                    _currPiece = tmpPiece;
                }

                NextPiece();
                _map.RemoveRows();
                Invalidate();
                return;
            }

            tmpPiece = rotate ? _currPiece.Rotate() : _currPiece.Move(dX, dY);
            if (!_map.CheckCollision(tmpPiece))
            {
                _currPiece = tmpPiece;
            }

            Invalidate();
        }