Exemplo n.º 1
0
        private void HandleKeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.Escape:
                Application.Exit();
                break;

            case Keys.W:
                controller.HandleMoveRequest("up");
                break;

            case Keys.A:
                controller.HandleMoveRequest("left");
                break;

            case Keys.S:
                controller.HandleMoveRequest("down");
                break;

            case Keys.D:
                controller.HandleMoveRequest("right");
                break;

            default:
                controller.HandleMoveRequest("none");
                break;
            }

            // Prevent other key handlers from running
            e.SuppressKeyPress = true;
            e.Handled          = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Key down handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleKeyDown(object sender, KeyEventArgs e)
        {
            // Close
            if (e.KeyCode == Keys.Escape)
            {
                Application.Exit();
            }

            // Movement keys
            if (e.KeyCode == Keys.W)
            {
                theController.HandleMoveRequest(sender, "up");
            }

            else if (e.KeyCode == Keys.A)
            {
                theController.HandleMoveRequest(sender, "left");
            }

            else if (e.KeyCode == Keys.S)
            {
                theController.HandleMoveRequest(sender, "down");
            }

            else if (e.KeyCode == Keys.D)
            {
                theController.HandleMoveRequest(sender, "right");
            }

            // FPS Toggle
            else if (e.KeyCode == Keys.F)
            {
                theController.ToggleFPS();
            }

            // Prevent other key handlers from running
            e.SuppressKeyPress = true;
            e.Handled          = true;
        }