NewGameSubMenu.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 Microsoft.Xna.Framework;
  12. using GameStateManagement;
  13. #endregion
  14. namespace MemoryMadness
  15. {
  16. class NewGameSubMenuScreen : MenuScreen
  17. {
  18. #region Initializations
  19. public NewGameSubMenuScreen()
  20. : base("")
  21. {
  22. // Create our menu entries.
  23. MenuEntry newGameMenuEntry = new MenuEntry("New Game");
  24. MenuEntry loadGameMenuEntry = new MenuEntry("Load");
  25. // Hook up menu event handlers.
  26. newGameMenuEntry.Selected += NewGameMenuEntrySelected;
  27. loadGameMenuEntry.Selected += LoadGameMenuEntrySelected;
  28. // Add entries to the menu.
  29. MenuEntries.Add(newGameMenuEntry);
  30. MenuEntries.Add(loadGameMenuEntry);
  31. }
  32. #endregion
  33. #region Update
  34. /// <summary>
  35. /// Respond to "Load Game" Item Selection
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. void LoadGameMenuEntrySelected(object sender, EventArgs e)
  40. {
  41. foreach (GameScreen screen in ScreenManager.GetScreens())
  42. screen.ExitScreen();
  43. ScreenManager.AddScreen(new LoadingAndInstructionsScreen(false), null);
  44. }
  45. /// <summary>
  46. /// Respond to "New Game" Item Selection
  47. /// </summary>
  48. /// <param name="sender"></param>
  49. /// <param name="e"></param>
  50. void NewGameMenuEntrySelected(object sender, EventArgs e)
  51. {
  52. if (PhoneApplicationService.Current.State.ContainsKey("CurrentLevel"))
  53. {
  54. PhoneApplicationService.Current.State.Remove("CurrentLevel");
  55. }
  56. LoadGameMenuEntrySelected(sender, e);
  57. }
  58. /// <summary>
  59. /// Handle the back button and return to the main menu.
  60. /// </summary>
  61. /// <param name="playerIndex"></param>
  62. protected override void OnCancel(PlayerIndex playerIndex)
  63. {
  64. foreach (GameScreen screen in ScreenManager.GetScreens())
  65. screen.ExitScreen();
  66. ScreenManager.AddScreen(new BackgroundScreen(false), null);
  67. ScreenManager.AddScreen(new MainMenuScreen(), null);
  68. }
  69. #endregion
  70. }
  71. }