コード例 #1
0
        public HighScoreScreen(Game game)
        {
            //TODO: Add HighScore initialization
            /* Step 1: Attach the storage to the game, and sign up for events for highscores saved/loaded. */
            Storage st = Storage.Attach(game, false);
            st.HighscoresChanged += this.HighscoresChanged;
            st.LoadComplete += new EventHandler(st_LoadComplete);
            st.NewHighscoreFound += new HighscoreEventHandler(st_NewHighscoreFound);
            st.SaveComplete += new EventHandler(st_SaveComplete);
            st.UserRefusedStorage += new EventHandler(st_UserRefusedStorage);
            /* If you don't sign up for StorageDeviceNeeded, the component can do default management of
             * storage devices using the standard Xna storage device selection dialog.
             */
            if (!st.StartLoading())
            {
                st.ReselectStorage();
            }

            /* Step 2: Attach the network component to the game. This must be done after the storage
             * component has been attached.
             * */
            Network nw = Network.Attach(game);
            /* ShareSomeHighscores() is the easy way to make networked highscore sharing work. There
             * are more advanced versions too, especally useful if you also want to support network
             * play in your game. See the file in question for those.
             */
            nw.ShareSomeHighscores();
            nw.SessionDisconnected += new EventHandler(nw_SessionDisconnected);
            nw.SessionEstablished += new SessionEstablishedHandler(nw_SessionEstablished);
            nw.TryingConnection += new EventHandler(nw_TryingConnection);
            nw.GamerJoined += new GamerEventHandler(nw_GamerJoined);
            nw.GamerLeft += new GamerEventHandler(nw_GamerLeft);
            network = nw;
        }
コード例 #2
0
 /* To instantiate network highscores, call Network.Attach(yourGame). This
  * assumes that a Storage component has already been attached to your game.
  */
 public static Network Attach(Game game)
 {
     if (game == null)
       {
     throw new ArgumentNullException("You must pass a valid game to Network.Attach()");
       }
       Storage st = null;
       foreach (GameComponent gc in game.Components)
       {
     if (typeof(Storage).IsAssignableFrom(gc.GetType()))
     {
       st = (Storage)gc;
     }
       }
       if (st == null)
       {
     //  I can't really do it automatically, because there are too many configuration
     //  options involved -- and disposing the Storage that would happen if the user
     //  configured storage after I created it would make it extra complicated
     throw new InvalidOperationException("You must attach Storage before you attach Network!");
       }
       storage = st;
       Instance = new Network(game);
       return Instance;
 }