/// <summary> /// Ulozeni hry /// </summary> /// <param name="gamename"></param> /// <param name="objectToSerialize"></param> public void SerializeGame(string gamename, GameSerialize objectToSerialize) { string filename = Path.Combine(Session.GameRef.Content.RootDirectory, "Saves", gamename); FileStream stream = new FileStream(filename, FileMode.Create); XmlSerializer serializer = new XmlSerializer(typeof(GameSerialize)); serializer.Serialize(stream, objectToSerialize); stream.Close(); }
/// <summary> /// Metoda slouzici pro ulozeni hry /// </summary> /// <param name="gamename"></param> public static void SaveGame(string gamename) { Session.GameData = new GameSerialize(); Session.GameData.mapName = "map.xml"; Session.GameData.hero = Session.CurrentHero; Session.GameData.cam = Session.Camera; Session.GameData.keys = Session.Keys; Session.GameData.units = Session.Units; Session.GameData.frontSplatter = Session.FrontMap.mapLayers[1]; try { Serializer ser = new Serializer(); ser.SerializeGame(gamename, Session.GameData); } catch (Exception ex) { string message = ex.Message; } }
/// <summary> /// Metoda slouzici pro nahrani hry /// </summary> /// <param name="gamename"></param> public static void LoadGame(string gamename) { GameSerialize ob = new GameSerialize(); try { Serializer ser = new Serializer(); ob = ser.DeSerializeGame(gamename); LoadMapAndTextures(ob.mapName); LoadHeroSprite(ob.hero.Gender); //Overrides Units loaded from MapSerialize Units = new List<Unit>(); foreach (Unit item in ob.units) { Unit klon = baseUnits[item.Name].Clone(item.Notoriety, item.Cell.X, item.Cell.Y); Session.FrontMap.GetTile(item.Cell).obj = klon; Units.Add(klon); } //Overrides Keys loaded from MapSerialize Keys = new List<GameKey>(); foreach (GameKey item in ob.keys) { GameKey klon = baseKeys[item.index].Clone(item.Cell.X, item.Cell.Y); Session.FrontMap.GetTile(item.Cell).obj = klon; Keys.Add(klon); } MapLayer frontPath = new MapLayer(Session.MapProps.FrontSizeX, Session.MapProps.FrontSizeY); for (int y = 0; y < frontPath.Height; y++) { for (int x = 0; x < frontPath.Width; x++) { Tile tile = new Tile(-1, -1, y, x); frontPath.SetTile(x, y, tile); } } Session.FrontMap.mapLayers.Add(frontPath); Session.CurrentHero = new Hero(ob.hero, playerSpriteHero); Session.CurrentHero.units = new List<Unit>(); foreach (Unit item in ob.hero.units) { Session.CurrentHero.units.Add(baseUnits[item.Name].Clone(item.Notoriety, item.Cell.X, item.Cell.Y, item.Attack, item.Defense, item.HitPoints, item.isInHero)); } Session.Camera = ob.cam; Session.FrontMap.mapLayers[1] = ob.frontSplatter; } catch (Exception ex) { string message = ex.Message; } }