Exemplo n.º 1
0
        /// <summary>
        /// Updates the state of the game.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);


            switch (gameMode)
            {
            case NetworkSessionComponent.GameMode.DeathMatch:
                UpdateDeathMatch();
                break;

            case NetworkSessionComponent.GameMode.TeamDeathmatch:
                UpdateTeamDeathMatch();
                break;

            case NetworkSessionComponent.GameMode.CaptureTheFlag:
                UpdateCTF();
                break;

            default:
                break;
            }

            if (IsActive)
            {
                localPlayer.Update(gameTime, mouseState, keyBoardState);

                camera.Position = localPlayer.Position + avatarOffset;

                camera.Update(localPlayer.Rotation, mouseState);

                // If we are in a network session, update it.
                if (networkSession.SessionType != NetworkSessionType.Local)
                {
                    UpdateNetworkSession();
                }
            }

            for (int i = 0; i < hud.messageList.Count; i++)
            {
                HUD.message currentMessage = hud.messageList[i];
                if (currentMessage.title == "b")
                {
                    currentMessage.text = "Pistol :" + bulletAmount + "/" + maxBullets;
                }
                else if (currentMessage.title == "p")
                {
                    currentMessage.text = "Player Score :" + PlayerScore.ToString();
                }
                else if (currentMessage.title == "e")
                {
                    currentMessage.text = "Enemy Score :" + enemyScore.ToString();
                }
                hud.messageList[i] = currentMessage;
            }



            // If we are in a network game, check if we should return to the lobby.
            if ((networkSession != null) && !IsExiting)
            {
                if (networkSession.SessionState == NetworkSessionState.Lobby)
                {
                    LoadingScreen.Load(ScreenManager, true,
                                       new BackgroundScreen(NetworkSessionComponent.Level.shipMap),
                                       new LobbyScreen(networkSession));
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Event handler for when the user selects ok on the "are you sure
 /// you want to quit" message box. This uses the loading screen to
 /// transition from the game back to the main menu screen.
 /// </summary>
 void ConfirmQuitMessageBoxAccepted(object sender, EventArgs e)
 {
     LoadingScreen.Load(ScreenManager, false, new BackgroundScreen(NetworkSessionComponent.Level.shipMap),
                        new MainMenuScreen());
 }
Exemplo n.º 3
0
        /// <summary>
        /// Activates the loading screen.
        /// </summary>
        public static void Load(ScreenManager screenManager, bool loadingIsSlow,
            params GameScreen[] screensToLoad)
        {
            // Tell all the current screens to transition off.
            foreach (GameScreen screen in screenManager.GetScreens())
                screen.ExitScreen();

            // Create and activate the loading screen.
            LoadingScreen loadingScreen = new LoadingScreen(screenManager,
                                                            loadingIsSlow,
                                                            screensToLoad);

            screenManager.AddScreen(loadingScreen);
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 void BackMenuEntrySelected(object sender, EventArgs e)
 {
     LoadingScreen.Load(ScreenManager, false, new BackgroundScreen(NetworkSessionComponent.Level.shipMap),
                        new MainMenuScreen());
 }
Exemplo n.º 5
0
        /// <summary>
        /// Internal method for leaving the network session. This disposes the
        /// session, removes the NetworkSessionComponent, and returns the user
        /// to the main menu screen.
        /// </summary>
        void LeaveSession()
        {
            // Remove the NetworkSessionComponent.
            Game.Components.Remove(this);

            // Remove the NetworkSession service.
            Game.Services.RemoveService(typeof(NetworkSession));

            // Dispose the NetworkSession.
            networkSession.Dispose();
            networkSession = null;

            // If we have a sessionEndMessage string explaining why the session has
            // ended (maybe this was a network disconnect, or perhaps the host kicked
            // us out?) create a message box to display this reason to the user.
            MessageBoxScreen messageBox;

            if (!string.IsNullOrEmpty(sessionEndMessage))
            {
                messageBox = new MessageBoxScreen(sessionEndMessage, false);
            }
            else
            {
                messageBox = null;
            }

            // At this point we normally want to return the user all the way to the
            // main menu screen. But what if they just joined a session? In that case
            // they went through this flow of screens:
            //
            //  - MainMenuScreen
            //  - CreateOrFindSessionsScreen
            //  - JoinSessionScreen (if joining, skipped if creating a new session)
            //  - LobbyScreeen
            //
            // If we have these previous screens on the history stack, and the user
            // backs out of the LobbyScreen, the right thing is just to pop off the
            // LobbyScreen and JoinSessionScreen, returning them to the
            // CreateOrFindSessionsScreen (we cannot just back up to the
            // JoinSessionScreen, because it contains search results that will no
            // longer be valid). But if the user is in gameplay, or has been in
            // gameplay and then returned to the lobby, the screen stack will have
            // been emptied.
            //
            // To do the right thing in both cases, we scan through the screen history
            // stack looking for a CreateOrFindSessionScreen. If we find one, we pop
            // any subsequent screens so as to return back to it, while if we don't
            // find it, we just reset everything and go back to the main menu.

            GameScreen[] screens = screenManager.GetScreens();

            // Look for the CreateOrFindSessionsScreen.
            for (int i = 0; i < screens.Length; i++)
            {
                if (screens[i] is CreateOrFindSessionScreen)
                {
                    // If we found one, pop everything since then to return back to it.
                    for (int j = i + 1; j < screens.Length; j++)
                    {
                        screens[j].ExitScreen();
                    }

                    // Display the why-did-the-session-end message box.
                    if (messageBox != null)
                    {
                        screenManager.AddScreen(messageBox);
                    }

                    return;
                }
            }

            // If we didn't find a CreateOrFindSessionsScreen, reset everything and
            // go back to the main menu. The why-did-the-session-end message box
            // will be displayed after the loading screen has completed.
            LoadingScreen.Load(screenManager, false, new BackgroundScreen(NetworkSessionComponent.Level.shipMap),
                               new MainMenuScreen(),
                               messageBox);
        }