Example #1
0
        /// <summary>
        /// Event handler notifies us when the network session has ended.
        /// </summary>
        void SessionEndedEventHandler(object sender, NetworkSessionEndedEventArgs e)
        {
            errorMessage = e.EndReason.ToString();

            networkSession.Dispose();
            networkSession = null;
        }
Example #2
0
 void returnToMenu()
 {
     if (networkSession != null)
     {
         networkSession.Dispose();
     }
     networkSession = null;
     started        = false;
     sessionType    = SessionType.None;
     GameLoop.setGameStateAndResetPlayers(GameState.Menu);
 }
Example #3
0
        public void HostSession()
        {
            if (_netSession != null)
            {
                _netSession.Dispose();
            }

            _netSession = null;
            _netSession = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 10);
            _netSession.AllowHostMigration  = true;
            _netSession.AllowJoinInProgress = true;
            _isHost = true;
            initialiseEventHandlers();
        }
Example #4
0
 void SessionEndedEventHandler(object sender, NetworkSessionEndedEventArgs e)
 {
     OnlineEventString = e.EndReason.ToString();
     networkSession.Dispose();
     networkSession = null;
     game.menus.GoTo("Score", true);
 }
        void GamerLeft(object sender, GamerLeftEventArgs e)
        {
            //dispose of network session
            networkSession.Dispose();
            networkSession = null;

            currentGameState = GameState.FindSession;
        }
Example #6
0
        public void LeaveSession()
        {
            if (networkSession != null)
            {
                if (networkSession.SessionState == NetworkSessionState.Playing)
                {
                    networkSession.EndGame();
                }

                if (networkSession.IsHost)
                {
                    networkSession.Dispose();
                }

                networkSession = null;
            }
        }
 /// <summary>
 /// Force the end of a network session so that a new one can be joined.
 /// </summary>
 public void EndSession()
 {
     if (networkSession != null)
     {
         networkSession.Dispose();
         networkSession = null;
     }
 }
Example #8
0
 public static void DisposeSession()
 {
     session.GamerJoined  -= GamerJoinedEventHandler;
     session.GamerLeft    -= GamerLeftEventHandler;
     session.GameEnded    -= GameEndedEventHandler;
     session.SessionEnded -= SessionEndedEventHandler;
     session.Dispose();
     session = null;
 }
 public static void CreateSession()
 {
     if (networkSession != null)
     {
         networkSession.Dispose();
     }
     SetStatus("Creating Session");
     try
     {
         networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 2);
         HookSessionEvents();
         SetStatus("Successfully Created Session");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         SetStatus(e.Message);
     }
 }
        public void CreateSession()
        {
            if (_session != null)
            {
                _session.Dispose();
            }
            if (Gamer.SignedInGamers.Count == 0)
            {
                SignIn();
            }
            else
            {
                _session              = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 2);
                _session.GamerJoined += new EventHandler <GamerJoinedEventArgs>(Host_GamerJoined);
                _session.GamerLeft   += new EventHandler <GamerLeftEventArgs>(Host_GamerLeft);

                GameMain.ChangeState(GameState.WaitingPlayers);

                IsHost = true;
            }
        }
Example #11
0
        /// <summary>
        /// Closes the Session and changes its SessionState to Closed
        /// </summary>
        public override void OnClosed()
        {
            _networkSession.GameStarted -= OnLiveSessionStarted;
            _networkSession.GamerJoined -= OnLivePlayerJoined;
            _networkSession.GamerLeft   -= OnLivePlayerLeft;
            _networkSession.GameEnded   -= OnLiveSessionEnded;

            if (_networkSession != null)
            {
                _networkSession.Dispose();
            }
        }
Example #12
0
        void restart()
        {
            youLoseSound.Play();
            deterministicGame.currentLevel.gameRestart = false;

            graphics.PreferredBackBufferHeight = 600;
            graphics.PreferredBackBufferWidth  = 800;
            graphics.ApplyChanges();


            musicControl.Restart();


            // Make the game object.  The game is currently called 'DuckSlaughterGame'
            deterministicGame = new DuckSlaughterGame();
            deterministicGame.ResetGame(playerIdentifiers, playerIdentifiers[0]);
            deterministicGame.LoadContent(Content);
            deterministicGame.Initialize();

            // Debugging setup
            lastPressedKeys = new List <Keys>();
            activePlayer    = playerIdentifiers[0];
            paused          = false;
            gameStarted     = false;


            //Added
            isHost   = false;
            chatText = "";

            reader.Close();
            writer.Close();

            networkSession.Dispose();

            networkSession = null;

            reader        = new PacketReader();
            writer        = new PacketWriter();
            chatlines     = 0;
            isChatting    = false;
            mouseChange   = false;
            buttonPressed = false;
            others        = new player[4];
            update        = true;
            gameStarted   = false;

            inMenu = true;
            startS.Show();
            helpS.Hide();
            activeS      = startS;
            releasedKeys = new List <Keys>();
        }
Example #13
0
        /// <summary>
        /// This event handler will be called whenever the game recieves an invite
        /// notification. This can occur when the user accepts an invite that was
        /// sent to them by a friend (pull mode), or if they choose the "Join
        /// Session In Progress" option in their friends screen (push mode).
        /// The handler should leave the current session (if any), then join the
        /// session referred to by the invite. It is not necessary to prompt the
        /// user before doing this, as the Guide will already have taken care of
        /// the necessary confirmations before the invite was delivered to you.
        /// </summary>
        void InviteAcceptedEventHandler(object sender, InviteAcceptedEventArgs e)
        {
            DrawMessage("Joining session from invite...");

            // Leave the current network session.
            if (networkSession != null)
            {
                networkSession.Dispose();
                networkSession = null;
            }

            try
            {
                // Join a new session in response to the invite.
                networkSession = NetworkSession.JoinInvited(maxLocalGamers);

                HookSessionEvents();
            }
            catch (Exception error)
            {
                errorMessage = error.Message;
            }
        }
        /// <summary>
        /// Leave the current network session.
        /// </summary>
        public void LeaveSession()
        {
            if (Session == null)
            {
                return;
            }

            if (!Session.IsDisposed)
            {
                Session.Dispose();
            }

            Session = null;
        }
Example #15
0
        /// <summary>
        /// Handles "Exit" menu item selection
        /// </summary>
        ///
        protected override void OnCancel(PlayerIndex playerIndex)
        {
            // Tear down our network session
            NetworkSession session = ScreenManager.Game.Services.GetService(typeof(NetworkSession)) as NetworkSession;

            if (session != null)
            {
                if (session.AllGamers.Count == 1)
                {
                    session.EndGame();
                }
                session.Dispose();
                ScreenManager.Game.Services.RemoveService(typeof(NetworkSession));
            }
            AudioManager.StopSounds();
            ScreenManager.AddScreen(new MainMenuScreen(), null);
            ExitScreen();
        }
Example #16
0
        /// <summary>
        /// Shuts down the component.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Remove the NetworkSessionComponent.
                Game.Components.Remove(this);

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

                // Dispose the NetworkSession.
                if (networkSession != null)
                {
                    networkSession.Dispose();
                    networkSession = null;
                }
            }

            base.Dispose(disposing);
        }
Example #17
0
        public void disposeNetworkSession()
        {
            if (networkSession != null)
            {
                networkSession.Dispose();
                networkSession = null;
            }

            foreach (LocalPlayer player in Global.localPlayers)
            {
                GamePad.SetVibration(player.playerIndex, 0, 0);
            }

            Global.graphics.GraphicsDevice.Viewport = new Viewport(Global.viewPort);
            Global.debugMode = false;
            Global.actionsong.Stop();
            Global.menusong.Play();
            Global.jetpack.Stop();
            Global.localPlayers.Clear();
            Global.remotePlayers.Clear();
            currentState = CurrentState.Idle;
        }
Example #18
0
        /// <summary>
        /// End remote debug command.
        /// </summary>
        void DisconnectedFromRemote()
        {
            DebugCommandUI commandUI = commandHost as DebugCommandUI;

            if (commandUI != null)
            {
                commandUI.Prompt = DebugCommandUI.DefaultPrompt;
            }

            commandHost.UnregisterCommand("quit");

            if (!IsHost)
            {
                commandHost.PopExecutioner();

                if (OwnsNetworkSession)
                {
                    NetworkSession.Dispose();
                    NetworkSession     = null;
                    OwnsNetworkSession = false;
                }
            }
        }
Example #19
0
        /// <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);
        }
Example #20
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(),
                               new MainMenuScreen(),
                               messageBox);
        }
Example #21
0
 public virtual void CloseSession()
 {
     Session.Dispose();
     Session = null;
 }
Example #22
0
        public void LoadAssets()
        {
            NetworkSession = ScreenManager.Game.Services.GetService(typeof(NetworkSession)) as NetworkSession;
            IsNetworking   = NetworkSession != null;

            // Load textures
            foregroundTexture    = Load <Texture2D> ("Textures/Backgrounds/gameplay_screen");
            cloud1Texture        = Load <Texture2D> ("Textures/Backgrounds/cloud1");
            cloud2Texture        = Load <Texture2D> ("Textures/Backgrounds/cloud2");
            mountainTexture      = Load <Texture2D> ("Textures/Backgrounds/mountain");
            skyTexture           = Load <Texture2D> ("Textures/Backgrounds/sky");
            defeatTexture        = Load <Texture2D> ("Textures/Backgrounds/defeat");
            victoryTexture       = Load <Texture2D> ("Textures/Backgrounds/victory");
            hudBackgroundTexture = Load <Texture2D> ("Textures/HUD/hudBackground");
            windArrowTexture     = Load <Texture2D> ("Textures/HUD/windArrow");
            ammoTypeTexture      = Load <Texture2D> ("Textures/HUD/ammoType");
            // Load font
            hudFont = Load <SpriteFont> ("Fonts/HUDFont");

            // Define initial cloud position
            cloud1Position = new Vector2(224 - cloud1Texture.Width, 32);
            cloud2Position = new Vector2(64, 90);

            // Define initial HUD positions
            playerOneHUDPosition = new Vector2(7, 7);
            computerHUDPosition  = new Vector2(613, 7);
            windArrowPosition    = new Vector2(345, 46);


            // Initialize human & other players
            if (IsNetworking)
            {
                if (NetworkSession.RemoteGamers.Count > 0)
                {
                    if (NetworkSession.IsHost)
                    {
                        playerOne = new Human(ScreenManager.Game, ScreenManager.SpriteBatch, PlayerSide.Left);
                        playerOne.Initialize();
                        playerOne.Name = NetworkSession.LocalGamers [0].Gamertag + " (host)";
                        playerTwo      = new Human(ScreenManager.Game, ScreenManager.SpriteBatch, PlayerSide.Right);
                        playerTwo.Initialize();
                        playerTwo.Name = NetworkSession.RemoteGamers [0].Gamertag;
                    }
                    else
                    {
                        playerOne = new Human(ScreenManager.Game, ScreenManager.SpriteBatch, PlayerSide.Left);
                        playerOne.Initialize();
                        playerOne.Name = NetworkSession.RemoteGamers [0].Gamertag + " (host)";
                        playerTwo      = new Human(ScreenManager.Game, ScreenManager.SpriteBatch, PlayerSide.Right);
                        playerTwo.Initialize();
                        playerTwo.Name = NetworkSession.LocalGamers [0].Gamertag;
                    }
                }
                else
                {
                    playerOne = new Human(ScreenManager.Game, ScreenManager.SpriteBatch, PlayerSide.Left);
                    playerOne.Initialize();
                    playerOne.Name = NetworkSession.LocalGamers [0].Gamertag + " (host)";
                    playerTwo      = new Human(ScreenManager.Game, ScreenManager.SpriteBatch, PlayerSide.Right);
                    playerTwo.Initialize();
                    playerTwo.Name = "Player 2";
                    IsNetworking   = false;
                    NetworkSession.Dispose();
                    NetworkSession = null;
                }
            }
            else
            {
                playerOne = new Human(ScreenManager.Game, ScreenManager.SpriteBatch, PlayerSide.Left);
                playerOne.Initialize();
                playerOne.Name = "Player 1";
                playerTwo      = new AI(ScreenManager.Game, ScreenManager.SpriteBatch);
                playerTwo.Initialize();
                playerTwo.Name = "Player 2";
            }

            // Identify enemies
            playerOne.Enemy = playerTwo;
            playerTwo.Enemy = playerOne;
        }
Example #23
0
 void QuitGameEventHandler(object sender, EventArgs e)
 {
     Session.Dispose();
     UnhookGameEvents();
 }
 void _networkSession_SessionEnded(object sender, NetworkSessionEndedEventArgs e)
 {
     _networkSession.Dispose();
     _networkSession = null;
 }