/// <summary> /// Updates the lobby. This method checks the GameScreen.IsActive /// property, so the game will stop updating when the pause menu is active, /// or if you tab away to a different application. /// </summary> public override void Update(Microsoft.Xna.Framework.GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { if (networkSession != null) { // update the network session try { networkSession.Update(); } catch (NetworkException ne) { System.Console.WriteLine( "Network failed to update: " + ne.ToString()); if (networkSession != null) { networkSession.Dispose(); networkSession = null; } } } // update the world if ((world != null) && !otherScreenHasFocus && !coveredByOtherScreen) { if (world.GameWon) { // unload the existing world world.Dispose(); world = null; // make sure that all of the ships have cleaned up foreach (NetworkGamer networkGamer in networkSession.AllGamers) { PlayerData playerData = networkGamer.Tag as PlayerData; if ((playerData != null) && (playerData.Ship != null)) { playerData.Ship.Die(null, true); } } // make sure the collision manager is up-to-date CollisionManager.Collection.ApplyPendingRemovals(); // create a new world world = new World(ScreenManager.GraphicsDevice, ScreenManager.Content, networkSession); } else if (world.GameExited) { if (!IsExiting) { ExitScreen(); } if (world != null) { world.Dispose(); world = null; } if (networkSession != null) { networkSession.Dispose(); networkSession = null; } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); return; } else { world.Update((float)gameTime.ElapsedGameTime.TotalSeconds, true); } } // update the menu entry text if (otherScreenHasFocus == false) { if ((networkSession.LocalGamers.Count > 0) && (networkSession.SessionState == NetworkSessionState.Lobby)) { if (!networkSession.LocalGamers[0].IsReady) { MenuEntries[0] = "Press X to Mark as Ready"; } else if (!networkSession.IsEveryoneReady) { MenuEntries[0] = "Waiting for all players to mark as ready..."; } else if (!networkSession.IsHost) { MenuEntries[0] = "Waiting for the host to start game..."; } else { MenuEntries[0] = "Starting the game..."; networkSession.StartGame(); } } else if (networkSession.SessionState == NetworkSessionState.Playing) { MenuEntries[0] = "Game starting..."; } // if the game is playing and the world is initialized, then start up if ((networkSession.SessionState == NetworkSessionState.Playing) && (world != null) && world.Initialized) { GameplayScreen gameplayScreen = new GameplayScreen(networkSession, world); gameplayScreen.ScreenManager = this.ScreenManager; ScreenManager.AddScreen(gameplayScreen); } } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); }