MainMenuScreen.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //-----------------------------------------------------------------------------
  2. // MainMenuScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. namespace AlienGameSample
  9. {
  10. /// <summary>
  11. /// The main menu screen is the first thing displayed when the game starts up.
  12. /// </summary>
  13. class MainMenuScreen : MenuScreen
  14. {
  15. /// <summary>
  16. /// Constructor fills in the menu contents.
  17. /// </summary>
  18. public MainMenuScreen()
  19. : base("Main")
  20. {
  21. // Create our menu entries.
  22. MenuEntry startGameMenuEntry = new MenuEntry("START GAME");
  23. MenuEntry exitMenuEntry = new MenuEntry("QUIT");
  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. /// <summary>
  32. /// Event handler for when the Play Game menu entry is selected.
  33. /// </summary>
  34. void StartGameMenuEntrySelected(object sender, EventArgs e)
  35. {
  36. ScreenManager.AddScreen(new GameplayScreen());
  37. }
  38. /// <summary>
  39. /// When the user cancels the main menu, ask if they want to exit the sample.
  40. /// </summary>
  41. protected override void OnCancel()
  42. {
  43. ScreenManager.Game.Exit();
  44. }
  45. }
  46. }