예제 #1
0
        public static GameData StartNewGame()
        {
            SetGameDataIndex();

            var newGameData = new GameData();

            SavedGameData[SaveGameIndex] = newGameData;

            return newGameData;
        }
예제 #2
0
        public static GameData Load()
        {
            var gameData = new GameData();

            using (var fileStream = SaveDataHelper.GetGameDataStream(FileAccess.Read))
            {
                using (var reader = new StreamReader(fileStream))
                {
                    int version = reader.ReadLine().ToInt();

                    switch (version)
                    {
                        case 1:
                            gameData.Scene = reader.ReadLine();

                            var x = reader.ReadLine().ToFloat();
                            var y = reader.ReadLine().ToFloat();
                            gameData.Location = new Vector2(x, y);

                            gameData.Gold = reader.ReadLine().ToInt();

                            gameData.Collectibles = new HashSet<string>();
                            int numCollectibles = reader.ReadLine().ToInt();
                            if (numCollectibles > 0)
                            {
                                for (int i = 0; i < numCollectibles; i++)
                                    gameData.Collectibles.Add(reader.ReadLine());
                            }

                            gameData.StoryProgressions = new HashSet<string>();
                            int numProgressions = reader.ReadLine().ToInt();
                            if (numProgressions > 0)
                            {
                                for (int i = 0; i < numProgressions; i++)
                                    gameData.StoryProgressions.Add(reader.ReadLine());
                            }

                            int partyMemberCount = reader.ReadLine().ToInt();
                            for (int i = 0; i < partyMemberCount; i++)
                            {
                                var partyMember = new PlayerSerializer(reader).Read();
                                gameData.Party[i] = partyMember;
                            }

                            break;
                        default:
                            break;
                    }
                }

                fileStream.Close();
            }

            return gameData;
        }