Exemplo n.º 1
0
        /// <summary>
        /// Handle the input for the menu screen.
        /// </summary>
        /// <param name="input"></param>
        public override void HandleInput(InputHandler input)
        {
            //Move to previous entry
            if (input.IsNewKeyPress(Keys.Up, false))
            {
                selectedEntry--;

                if (selectedEntry < 0)
                    selectedEntry = menuEntries.Count - 1;
            }

            //Move to next entry
            if (input.IsNewKeyPress(Keys.Down, false))
            {
                selectedEntry++;

                if (selectedEntry > menuEntries.Count - 1)
                    selectedEntry = 0;
            }

            //Select an entry
            if (input.IsNewKeyPress(Keys.Enter, false))
            {
                menuEntries[selectedEntry].OnSelectEntry();
            }
        }
Exemplo n.º 2
0
 public ScreenManager(Game game)
     : base(game)
 {
     try
     {
         inputHandler = (InputHandler)game.Services.GetService(typeof(IInputHandler));
     }
     catch (Exception e)
     {
         throw new NullReferenceException("Could not locate InputHandler service.", e);
     }
 }
Exemplo n.º 3
0
 public virtual void HandleInput(InputHandler input)
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Handles all the input controls.
        /// </summary>
        public override void HandleInput(InputHandler input)
        {
            //Control logic
            if (input.IsNewKeyPress(Keys.LeftAlt, false))
            {
                //Rotate clockwise
                currentLevel.RotateActiveBlock(RotationDirection.ClockWise);
            }
            if (input.IsNewKeyPress(Keys.LeftControl, false))
            {
                //Rotate counter clockwise
                currentLevel.RotateActiveBlock(RotationDirection.CounterClockWise);
            }
            if (input.IsNewKeyPress(Keys.Left, true))
            {
                //Move left
                currentLevel.MoveBlock(MovementDirection.Left);
            }
            if (input.IsNewKeyPress(Keys.Right, true))
            {
                //Move right
                currentLevel.MoveBlock(MovementDirection.Right);
            }
            if (input.IsNewKeyPress(Keys.Down, true))
            {
                //Move down
                currentLevel.MoveBlock(MovementDirection.Down);
            }
            if (input.IsNewKeyPress(Keys.Space, false))
            {
                //Drop the block
                while (currentLevel.BlockCanMove())
                {
                    currentLevel.MoveBlock(MovementDirection.Down);
                }
                //If the block is at the bottommost position, add the next block to the field.
                SetNextBlock();
            }

            //If Enter is pressed in any state of the screen that isn't Playing, restart the game.
            //This will be sufficient for now, because the only other States are Opening and GameOver.
            if (input.KeyIsPressed(Keys.Enter) && currentState != GameState.Playing)
            {
                this.Initialize();
                currentState = GameState.Playing;
            }
        }