コード例 #1
0
ファイル: SaveGameData.cs プロジェクト: ServerGame/NullQuest
        public static SaveGameData FromGameWorld(GameWorld gameWorld)
        {
            var saveGameData = new SaveGameData
            {
                BossesDefeated = new List<string>(gameWorld.BossesDefeated),
                CharacterName = gameWorld.Player.Name,
                Class = gameWorld.Player.Class.Name,
                CurrentDungeonLevel = gameWorld.CurrentDungeonLevel,
                Id = gameWorld.SaveGameId,
                Level = gameWorld.Player.Level,
                Gold = gameWorld.Player.Gold,
                Experience = gameWorld.Player.Experience,
                Race = gameWorld.Player.Race.Name,
                Stats = gameWorld.Player.BaseStats,
                TotalNumberOfMonstersDefeated = gameWorld.TotalNumberOfMonstersDefeated,
                Weapon = gameWorld.Player.Weapon,
                Inventory = gameWorld.Player.Inventory.ToList(),
                SpellBook = gameWorld.Player.SpellBook.ToList()
            };

            return saveGameData;
        }
コード例 #2
0
 private void Persist(SaveGameData[] savedGames)
 {
     using (var writer = _fileAccess.CreateWriter())
     {
         _serializer.Serialize(writer, savedGames);
     }
 }
コード例 #3
0
 public void SaveGame(SaveGameData saveGameData)
 {
     var index = _savedGames.Select((x, i) => new { SavedGameData = x, Index = i }).First(x => x.SavedGameData.Id == saveGameData.Id).Index;
     _savedGames[index] = saveGameData;
     Persist(_savedGames);
 }
コード例 #4
0
        private void Persist(SaveGameData[] savedGames)
        {
            var i = 0;

            while (true)
            {
                try
                {
                    using (var writer = _fileAccess.CreateWriter())
                    {
                        _serializer.Serialize(writer, savedGames);
                        return;
                    }
                }
                catch
                {
                    Thread.Sleep(1);

                    if (++i > 10)
                    {
                        throw;
                    }
                }
            }
        }