Exemplo n.º 1
0
        /// <summary>
        /// Zapisuje stan gry do pliku
        /// </summary>
        /// <param name="saveName">Nazwa pliku</param>
        /// <param name="data">Dane do zapisu</param>
        public static void SaveGame(string saveName, SaveData data)
        {
            var path = GetSaveFilePath(saveName);
            var directory = Path.GetDirectoryName(path);
            if (!Directory.Exists(directory))
                Directory.CreateDirectory(directory);

            data.Serialize(path);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Konstruktor służący do ładowania poziomu oraz odtworzenia zapisanego stanu gry.
 /// </summary>
 /// <param name="game"></param>
 /// <param name="saveData"></param>
 public Level(MinerGame game, SaveData saveData)
 {
     _game = game;
     Name = saveData.LevelName;
     _saveData = saveData;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Zwraca dane o poziomie oraz obiektach znajdujących się na nim w celu zapisu gry do pliku.
        /// </summary>
        /// <returns></returns>
        public SaveData GetSaveData()
        {
            var gameObjects = new List<GameObjectData>();
            gameObjects.AddRange(_explosives.Select(x => new GameObjectData()
                {
                    Type = x.Type,
                    Position = x.Position
                }));
            gameObjects.AddRange(_machines.Select(x => new GameObjectData()
                {
                    Type = x.Type,
                    Position = x.Position
                }));
            gameObjects.AddRange(_collectibles.Select(x => new GameObjectData()
                {
                    Type = x.Type,
                    Position = x.Position
                }));

            var playerData = new PlayerData()
            {
                Position = Player.Position,
                Dynamite = Player.Dynamite,
                Lives = Player.Lives,
                Oxygen = Player.Oxygen,
                Points = Player.Points,
                Type = Player.Type
            };

            var saveData = new SaveData()
            {
                GameObjects = gameObjects,
                KeyCollected = _keyCollected,
                LevelName = Name,
                Player = playerData
            };

            return saveData;
        }