private static void RunGame() { if (!Hosting) { InputManager.Initialize(); Chat.Initialize(); LocalClient.Initialize(Ip, Port); Console.Clear(); while (true) { Update(); Draw(); } } else { // Start a server and maintain it. Listener.Initialize(); Server.Initialize(); Console.Clear(); Console.WriteLine("Started server.\n"); while (true) { Server.Update(); } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { IsMouseVisible = true; TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 1000 / 120); InactiveSleepTime = TargetElapsedTime; Window.Title = "XNA Multiplayer Game - "; if (Program.Hosting) { Window.Title += "Listen server, hosting on port 5555."; } else { Window.Title += "Client, joined at " + Program.Ip + ":5555."; } // Initialize classes & members. sb = new SpriteBatch(GraphicsDevice); Helper.Initialize(this); ResourceHelper.Initialize(Content); // Load content. _backgroundWallTexture = ResourceHelper.LoadTexture("Backgrounds\\Veins"); _platformTexture = ResourceHelper.LoadTexture("Objects\\Platform"); _vignette = ResourceHelper.LoadTexture("Gui\\Vignette"); Platform.Texture = ResourceHelper.LoadTexture("Objects\\Platform"); Player.Texture = ResourceHelper.LoadTexture("Objects\\Player"); // TODO: Add your initialization logic here Helper.Initialize(this); _graphics.PreferredBackBufferWidth = 768; _graphics.PreferredBackBufferHeight = 768; _graphics.PreferMultiSampling = true; _graphics.SynchronizeWithVerticalRetrace = false; _graphics.ApplyChanges(); IsFixedTimeStep = true; BackgroundWall = new BackgroundWall(_backgroundWallTexture, DefaultScrollSpeed); if (Program.Hosting) { Server.Initialize(); } PlatformWorld.Initialize(DefaultScrollSpeed); LocalClient.Initialize(); base.Initialize(); }