示例#1
0
        public static void Load()
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream($"Saves\\Profile{Settings.Profile}.map", FileMode.OpenOrCreate))
            {
                MapSave ms = (MapSave)formatter.Deserialize(fs);
                ms.Load();
                Console.WriteLine("Карта десериализована");
            }

            PlayerSave playerSave = new PlayerSave()
            {
                X     = Program.player.x,
                Y     = Program.player.y,
                A     = Program.player.a,
                MapAX = Program.player.mapActivator.X,
                MapAY = Program.player.mapActivator.Y
            };

            using (FileStream fs = new FileStream($"Saves\\Profile{Settings.Profile}.plr", FileMode.OpenOrCreate))
            {
                PlayerSave ps = (PlayerSave)formatter.Deserialize(fs);
                ps.Load();
                Console.WriteLine("Игрок десериализован");
            }
        }
示例#2
0
        public static void Save()
        {
            Coord Start = (Coord)Program.map.In.Clone();
            Coord End   = (Coord)Program.map.Out.Clone();

            MapSave mapSave = new MapSave()
            {
                Map       = (bool[, ])Program.map.map.Clone(),
                StartX    = Start.x,
                StartY    = Start.y,
                EndX      = End.x,
                EndY      = End.y,
                MapHeight = Program.map.Height,
                MapWidth  = Program.map.Width,
                isVisible = Program.map.isVisible
            };

            BinaryFormatter formatter = new BinaryFormatter();

            Directory.CreateDirectory("Saves");
            using (FileStream fs = new FileStream($"Saves\\Profile{Settings.Profile}.map", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, mapSave);
                Console.WriteLine("Карта сериализована");
            }

            PlayerSave playerSave = new PlayerSave()
            {
                X     = Program.player.x,
                Y     = Program.player.y,
                A     = Program.player.a,
                MapAX = Program.player.mapActivator.X,
                MapAY = Program.player.mapActivator.Y
            };

            using (FileStream fs = new FileStream($"Saves\\Profile{Settings.Profile}.plr", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, playerSave);
                Console.WriteLine("Игрок сериализован");
            }
        }