Game.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Game.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 Microsoft.Xna.Framework;
  11. using Microsoft.Xna.Framework.Graphics;
  12. using Microsoft.Xna.Framework.GamerServices;
  13. using Microsoft.Xna.Framework.Net;
  14. #endregion
  15. namespace NetworkStateManagement
  16. {
  17. /// <summary>
  18. /// Sample showing how to manage the different game states involved in
  19. /// implementing a networked game, with menus for creating, searching,
  20. /// and joining sessions, a lobby screen, and the game itself. This main
  21. /// game class is extremely simple: all the interesting stuff happens
  22. /// in the ScreenManager component.
  23. /// </summary>
  24. public class NetworkStateManagementGame : Microsoft.Xna.Framework.Game
  25. {
  26. #region Fields
  27. GraphicsDeviceManager graphics;
  28. ScreenManager screenManager;
  29. // By preloading any assets used by UI rendering, we avoid framerate glitches
  30. // when they suddenly need to be loaded in the middle of a menu transition.
  31. static readonly string[] preloadAssets =
  32. {
  33. "gradient",
  34. "cat",
  35. "chat_ready",
  36. "chat_able",
  37. "chat_talking",
  38. "chat_mute",
  39. };
  40. #endregion
  41. #region Initialization
  42. /// <summary>
  43. /// The main game constructor.
  44. /// </summary>
  45. public NetworkStateManagementGame()
  46. {
  47. Content.RootDirectory = "Content";
  48. graphics = new GraphicsDeviceManager(this);
  49. graphics.PreferredBackBufferWidth = 1067;
  50. graphics.PreferredBackBufferHeight = 600;
  51. // Create components.
  52. screenManager = new ScreenManager(this);
  53. Components.Add(screenManager);
  54. Components.Add(new MessageDisplayComponent(this));
  55. Components.Add(new GamerServicesComponent(this));
  56. // Activate the first screens.
  57. screenManager.AddScreen(new BackgroundScreen(), null);
  58. screenManager.AddScreen(new MainMenuScreen(), null);
  59. // Listen for invite notification events.
  60. NetworkSession.InviteAccepted += (sender, e)
  61. => NetworkSessionComponent.InviteAccepted(screenManager, e);
  62. // To test the trial mode behavior while developing your game,
  63. // uncomment this line:
  64. // Guide.SimulateTrialMode = true;
  65. }
  66. /// <summary>
  67. /// Loads graphics content.
  68. /// </summary>
  69. protected override void LoadContent()
  70. {
  71. foreach (string asset in preloadAssets)
  72. {
  73. Content.Load<object>(asset);
  74. }
  75. }
  76. #endregion
  77. #region Draw
  78. /// <summary>
  79. /// This is called when the game should draw itself.
  80. /// </summary>
  81. protected override void Draw(GameTime gameTime)
  82. {
  83. graphics.GraphicsDevice.Clear(Color.Black);
  84. // The real drawing happens inside the screen manager component.
  85. base.Draw(gameTime);
  86. }
  87. #endregion
  88. }
  89. #region Entry Point
  90. /// <summary>
  91. /// The main entry point for the application.
  92. /// </summary>
  93. static class Program
  94. {
  95. static void Main()
  96. {
  97. using (NetworkStateManagementGame game = new NetworkStateManagementGame())
  98. {
  99. game.Run();
  100. }
  101. }
  102. }
  103. #endregion
  104. }