2 using System.Collections.Generic;
4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Audio;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.GamerServices;
8 using Microsoft.Xna.Framework.Graphics;
9 using Microsoft.Xna.Framework.Input;
10 using Microsoft.Xna.Framework.Media;
11 using Microsoft.Xna.Framework.Net;
12 using Microsoft.Xna.Framework.Storage;
17 /// This is the main type for your game
19 public class XnaGame : Microsoft.Xna.Framework.Game
21 GraphicsDeviceManager graphics;
22 SpriteBatch spriteBatch;
24 NetworkManager networkGame;
25 IScreenManager screenManager;
26 IDeterministicGame deterministicGame;
30 graphics = new GraphicsDeviceManager(this);
31 Content.RootDirectory = "Content";
33 Components.Add(new GamerServicesComponent(this));
35 screenManager = new ScreenManager();
36 deterministicGame = new Game();
37 networkGame = new NetworkManager(screenManager, deterministicGame);
39 Vector2 size = deterministicGame.PreferredScreenSize;
40 graphics.PreferredBackBufferWidth = (int)size.X;
41 graphics.PreferredBackBufferHeight = (int)size.Y;
42 graphics.ApplyChanges();
46 /// Allows the game to perform any initialization it needs to before starting to run.
47 /// This is where it can query for any required services and load any non-graphic
48 /// related content. Calling base.Initialize will enumerate through any components
49 /// and initialize them as well.
51 protected override void Initialize()
53 IsFixedTimeStep = true;
54 TargetElapsedTime = networkGame.TargetTimeSpan;
61 /// LoadContent will be called once per game and is the place to load
62 /// all of your content.
64 protected override void LoadContent()
66 // Create a new SpriteBatch, which can be used to draw textures.
67 spriteBatch = new SpriteBatch(GraphicsDevice);
69 screenManager.LoadContent(Content, graphics);
70 deterministicGame.LoadContent(Content);
74 /// UnloadContent will be called once per game and is the place to unload
77 protected override void UnloadContent()
79 screenManager.UnloadContent();
80 deterministicGame.UnloadContent();
84 /// Allows the game to run logic such as updating the world,
85 /// checking for collisions, gathering input, and playing audio.
87 /// <param name="gameTime">Provides a snapshot of timing values.</param>
88 protected override void Update(GameTime gameTime)
90 networkGame.Update(gameTime);
92 base.Update(gameTime);
96 /// This is called when the game should draw itself.
98 /// <param name="gameTime">Provides a snapshot of timing values.</param>
99 protected override void Draw(GameTime gameTime)
102 networkGame.Draw(gameTime, spriteBatch);