Пример #1
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;
        }