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;
60 /// LoadContent will be called once per game and is the place to load
61 /// all of your content.
63 protected override void LoadContent()
65 // Create a new SpriteBatch, which can be used to draw textures.
66 spriteBatch = new SpriteBatch(GraphicsDevice);
68 screenManager.LoadContent(Content, graphics);
69 deterministicGame.LoadContent(Content);
73 /// UnloadContent will be called once per game and is the place to unload
76 protected override void UnloadContent()
78 screenManager.UnloadContent();
79 deterministicGame.UnloadContent();
83 /// Allows the game to run logic such as updating the world,
84 /// checking for collisions, gathering input, and playing audio.
86 /// <param name="gameTime">Provides a snapshot of timing values.</param>
87 protected override void Update(GameTime gameTime)
89 networkGame.Update(gameTime);
91 base.Update(gameTime);
95 /// This is called when the game should draw itself.
97 /// <param name="gameTime">Provides a snapshot of timing values.</param>
98 protected override void Draw(GameTime gameTime)
100 GraphicsDevice.Clear(Color.Red);
103 networkGame.Draw(gameTime, spriteBatch);