MainMenuScreen.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // MainMenuScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using GameStateManagement;
  15. using Microsoft.Xna.Framework;
  16. #endregion
  17. namespace CatapultGame
  18. {
  19. class MainMenuScreen : MenuScreen
  20. {
  21. #region Initialization
  22. public MainMenuScreen()
  23. : base(String.Empty)
  24. {
  25. IsPopup = true;
  26. // Create our menu entries.
  27. MenuEntry startGameMenuEntry = new MenuEntry("Play");
  28. MenuEntry exitMenuEntry = new MenuEntry("Exit");
  29. // Hook up menu event handlers.
  30. startGameMenuEntry.Selected += StartGameMenuEntrySelected;
  31. exitMenuEntry.Selected += OnCancel;
  32. // Add entries to the menu.
  33. MenuEntries.Add(startGameMenuEntry);
  34. MenuEntries.Add(exitMenuEntry);
  35. }
  36. #endregion
  37. #region Overrides
  38. protected override void UpdateMenuEntryLocations()
  39. {
  40. base.UpdateMenuEntryLocations();
  41. foreach (var entry in MenuEntries)
  42. {
  43. Vector2 position = entry.Position;
  44. position.Y += 60;
  45. entry.Position = position;
  46. }
  47. }
  48. #endregion
  49. #region Event Handlers for Menu Items
  50. /// <summary>
  51. /// Handles "Play" menu item selection
  52. /// </summary>
  53. /// <param name="sender"></param>
  54. /// <param name="e"></param>
  55. void StartGameMenuEntrySelected(object sender, EventArgs e)
  56. {
  57. ScreenManager.AddScreen(new InstructionsScreen(), null);
  58. }
  59. /// <summary>
  60. /// Handles "Exit" menu item selection
  61. /// </summary>
  62. ///
  63. protected override void OnCancel(PlayerIndex playerIndex)
  64. {
  65. ScreenManager.Game.Exit();
  66. }
  67. #endregion
  68. }
  69. }