コード例 #1
0
        /// <summary>
        /// Updates the lobby screen.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                    bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (!IsExiting)
            {
                if (networkSession.SessionState == NetworkSessionState.Playing)
                {
                    // Check if we should leave the lobby and begin gameplay.
                    // We pass null as the controlling player, because the networked
                    // gameplay screen accepts input from any local players who
                    // are in the session, not just a single controlling player.
                    LoadingScreen.Load(ScreenManager, true, null,
                                       new GameplayScreen(networkSession));
                }
                else if (networkSession.IsHost && networkSession.IsEveryoneReady)
                {
                    // The host checks whether everyone has marked themselves
                    // as ready, and starts the game in response.
                    networkSession.StartGame();
                }
            }

            if (!localGamer.HasLeftSession)
            {
                while (localGamer.IsDataAvailable)
                {
                    PacketReader reader = new PacketReader();
                    NetworkGamer sender;
                    localGamer.ReceiveData(reader, out sender);

                    // ignore packets from self
                    if (sender.Id != localGamer.Id)
                    {
                        sender.UpdateFromNetwork(reader);
                    }
                }

                // broadcast current data to everyone.
                localGamer.SendToNetwork();
            }
        }