MainMenuScreen.cs 1.9 KB

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