PauseScreen.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // PauseScreen.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 PauseScreen : MenuScreen
  20. {
  21. #region Fields
  22. GameScreen backgroundScreen;
  23. Player human;
  24. Player computer;
  25. bool prevHumanIsActive;
  26. bool prevCompuerIsActive;
  27. #endregion
  28. #region Initialization
  29. public PauseScreen(GameScreen backgroundScreen, Player human, Player computer)
  30. : base(String.Empty)
  31. {
  32. IsPopup = true;
  33. this.backgroundScreen = backgroundScreen;
  34. // Create our menu entries.
  35. MenuEntry startGameMenuEntry = new MenuEntry("Return");
  36. MenuEntry exitMenuEntry = new MenuEntry("Quit Game");
  37. // Hook up menu event handlers.
  38. startGameMenuEntry.Selected += StartGameMenuEntrySelected;
  39. exitMenuEntry.Selected += OnCancel;
  40. // Add entries to the menu.
  41. MenuEntries.Add(startGameMenuEntry);
  42. MenuEntries.Add(exitMenuEntry);
  43. this.human = human;
  44. this.computer = computer;
  45. // Preserve the old state of the game
  46. prevHumanIsActive = this.human.Catapult.IsActive;
  47. prevCompuerIsActive = this.computer.Catapult.IsActive;
  48. // Pause the game logic progress
  49. this.human.Catapult.IsActive = false;
  50. this.computer.Catapult.IsActive = false;
  51. AudioManager.PauseResumeSounds(false);
  52. }
  53. #endregion
  54. #region Overrides
  55. protected override void UpdateMenuEntryLocations()
  56. {
  57. base.UpdateMenuEntryLocations();
  58. foreach (var entry in MenuEntries)
  59. {
  60. Vector2 position = entry.Position;
  61. position.Y += 60;
  62. entry.Position = position;
  63. }
  64. }
  65. #endregion
  66. #region Event Handlers for Menu Items
  67. /// <summary>
  68. /// Handles "Return" menu item selection
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. void StartGameMenuEntrySelected(object sender, EventArgs e)
  73. {
  74. human.Catapult.IsActive = prevHumanIsActive;
  75. computer.Catapult.IsActive = prevCompuerIsActive;
  76. if (!(human as Human).isDragging)
  77. AudioManager.PauseResumeSounds(true);
  78. else
  79. {
  80. (human as Human).ResetDragState();
  81. AudioManager.StopSounds();
  82. }
  83. backgroundScreen.ExitScreen();
  84. ExitScreen();
  85. }
  86. /// <summary>
  87. /// Handles "Exit" menu item selection
  88. /// </summary>
  89. ///
  90. protected override void OnCancel(PlayerIndex playerIndex)
  91. {
  92. AudioManager.StopSounds();
  93. ScreenManager.AddScreen(new MainMenuScreen(), null);
  94. ExitScreen();
  95. }
  96. #endregion
  97. }
  98. }