Exemplo n.º 1
0
        /// <summary>
        /// Handle input
        /// </summary>
        /// <param name="gameTime">Snapshot of timing values</param>
        public override void HandleInput(GameTime gameTime)
        {
            base.HandleInput(gameTime);

            if (InputManager.Keyboard.IsKeyReleased(Keys.Escape) && _popupScreen == null)
            {
                _timeline.Stop();
                _popupScreen = new PauseScreen(this, _controller);
                this.ScreenManager.AddScreen(_popupScreen);

                _popupScreen.Exited += new EventHandler(_pauseScreen_Exited);
                return;
            }

            // Don't process game if ended
            if (_field.HasEnded)
            {
                return;
            }

            if (_controller.Action == ControllerAction.Time && _field.Score > 0)
            {
                _timeline.RewindFrame();
            }

            // Don't process if rewinding
            if (_timeline.IsRewindActive)
            {
                return;
            }

            // Action from the controller
            switch (_controller.Action)
            {
            case ControllerAction.Down:
                _field.CurrentBlock.MoveDown();
                break;

            case ControllerAction.Left:
                _field.CurrentBlock.MoveLeft();

                break;

            case ControllerAction.Right:
                _field.CurrentBlock.MoveRight();
                break;

            case ControllerAction.Drop:
                _field.CurrentBlock.Drop();
                break;

            case ControllerAction.RotateCW:
                if (_field.CurrentBlock.RotateRight())
                {
                    _rotateSound.Play();
                }
                break;

            case ControllerAction.RotateCCW:
                if (_field.CurrentBlock.RotateLeft())
                {
                    _rotateSound.Play();
                }
                break;

            case ControllerAction.Hold:
                var oldHoldBlock = _field.HoldBlock;
                if (_field.SwitchHoldingBlock())
                {
                    var holdBlock = _field.HoldBlock;
                    _timeline.Add(new Event()
                    {
                        Apply = () => {
                            _spriteHoldBlock.SetBlock(holdBlock);
                            HoldBlock_OnTypeChanged(holdBlock.Type);
                        },

                        Undo = () => {
                            _spriteHoldBlock.SetBlock(oldHoldBlock);

                            if (oldHoldBlock != null)
                            {
                                HoldBlock_OnTypeChanged(oldHoldBlock.Type);
                            }
                        }
                    });
                }
                break;
            }
        }