예제 #1
0
        void SaveGameData()
        {
            if (gameState == GameState.Playing || gameState == GameState.Paused || gameState == GameState.Fighting ||
                previousGameState == GameState.Playing || previousGameState == GameState.Paused || previousGameState == GameState.Fighting)
            {
                GameData data = new GameData();

                data.GameState = gameState;
                data.PreviousGameState = previousGameState;

                data.PastSteps = pastSteps;
                data.ShowPath = showPath;
                data.Count = count;
                data.FightCounter = fightCounter;
                data.Faith = faith;
                data.MinimumMoves = minimumMoves;

                data.PlayerAnimationActive = playerAnimation.Active;
                data.FightAnimationActive = fightAnimation.Active;
                data.WinAnimationActive = winAnimation.Active;
                data.LoseAnimationActive = loseAnimation.Active;

                data.EnemyX = new List<int>();
                data.EnemyY = new List<int>();

                data.ItemX = new List<int>();
                data.ItemY = new List<int>();
                data.ItemType = new List<Maze.State>();

                foreach (KeyValuePair<Vector2, Enemy> kvp in enemies)
                {
                    data.EnemyX.Add((int)kvp.Value.Position.X);
                    data.EnemyY.Add((int)kvp.Value.Position.Y);
                }

                foreach (KeyValuePair<Vector2, Item> kvp in items)
                {
                    data.ItemX.Add((int)kvp.Value.Position.X);
                    data.ItemY.Add((int)kvp.Value.Position.Y);
                    data.ItemType.Add(kvp.Value.Type);
                }

                data.PlayerX = (int)player.Position.X;
                data.PlayerY = (int)player.Position.Y;
                data.Steps = player.Steps;
                data.Score = player.Score;
                data.HasSword = player.HasSword;
                data.HasTreasure = player.HasTreasure;
                data.Energy = player.Energy;

                IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("savegame.sav", FileMode.Create, store))
                {
                    SharpSerializer serializer = new SharpSerializer(true);
                    serializer.Serialize(data, stream);
                }
            }
        }
예제 #2
0
        GameData LoadGameData()
        {
            GameData data = new GameData();

            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

            if (store.FileExists("savegame.sav"))
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("savegame.sav", FileMode.Open, store))
                {
                    SharpSerializer serializer = new SharpSerializer(true);
                    data = (GameData)serializer.Deserialize(stream);
                }
            }

            return data;
        }