示例#1
0
        public static GameState Load(string filename, GameState state)
        {
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

            if (store.FileExists(DefaultSaveGameFile)) // Check if file exists
            {
                var save = new IsolatedStorageFileStream(DefaultSaveGameFile, FileMode.Open, store);
                var reader = new BinaryReader(save);
                var game = new SavedGame();
                game.Money = reader.ReadInt32();
                game.Gun = reader.ReadString();
                game.Shield = reader.ReadString();
                game.Body = reader.ReadString();
                game.NextLevelIndex = reader.ReadInt32();
                game.Plazma = reader.ReadString();
                game.Medcit = reader.ReadString();
                game.Spikes = reader.ReadString();
                game.Tablet = reader.ReadString();
                reader.Close();
                PopulateWithLoadedData(state, game);
            }
            return state;
        }
示例#2
0
        private static void PopulateWithLoadedData(GameState sourceState, SavedGame loadedGame)
        {
            sourceState.Inventory.Body = loadedGame.Body;
            sourceState.Inventory.Gun = loadedGame.Gun;
            sourceState.Inventory.Shield = loadedGame.Shield;
            sourceState.Inventory.Money = loadedGame.Money;
            sourceState.GameStory.NextLevelIndex = loadedGame.NextLevelIndex;
            sourceState.Inventory.FrontWeapon = loadedGame.Plazma;
            sourceState.Inventory.Medcit = loadedGame.Medcit;
            sourceState.Inventory.Spike = loadedGame.Spikes;
            sourceState.Inventory.Tablet = loadedGame.Tablet;

            return;
        }
示例#3
0
 private static SavedGame MapToSavedGame(GameState gameState)
 {
     var savedGame = new SavedGame
                         {
                             Body = gameState.Inventory.Body,
                             Gun = gameState.Inventory.Gun,
                             Shield = gameState.Inventory.Shield,
                             Money = gameState.Inventory.Money,
                             NextLevelIndex = gameState.GameStory.NextLevelIndex,
                             Plazma = gameState.Inventory.FrontWeapon,
                             Medcit = gameState.Inventory.Medcit,
                             Spikes = gameState.Inventory.Spike,
                             Tablet = gameState.Inventory.Tablet
                         };
     return savedGame;
 }