private static void SaveGame(FeudalGameEngine game) { var dto = new DTOGameSave() { Money = game.Money, PeasantsCount = game.PeasantsCount, Settings = new DTOGameSettingsSave() { MaxPeasantCount = game.Settings.MaxPeasantCount, PeasantsTargetCount = game.Settings.PeasantsTargetCount, PeasantSpawnChance = game.Settings.PeasantSpawnChance } }; var serializer = new DataContractJsonSerializer(typeof(DTOGameSave)); using var fileStream = new FileStream($"{Directory.GetCurrentDirectory()}\\save.json", FileMode.Truncate); serializer.WriteObject(fileStream, dto); }
//for load public FeudalGameEngine(DTOGameSave gameSave) { Settings = new FeudalGameSettings(gameSave.Settings); _peasantsCount = gameSave.PeasantsCount; Init(); }