//#---------------------------------------------------------- //# * Load Player Data //#---------------------------------------------------------- public static Game_Player LoadPlayerData() { Game_Player player = new Game_Player(); string[] rawSave = File.ReadAllText(PLAYER_SAVE_PATH).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); // load groups and units LoadIntoDeck(player.Deck, rawSave[0]); // load scores string[] scores = rawSave[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int level = 1; level <= Global.NUMBER_OF_LEVELS; level++) { player.SetLevelScore(level, Convert.ToInt32(scores[level - 1])); } // load unlocked units string[] unlockedUnits = rawSave[2].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string unitID in unlockedUnits) player.UnlockUnit(Convert.ToInt32(unitID)); return player; }
//#---------------------------------------------------------- //# * Save Player Data //#---------------------------------------------------------- public static void SavePlayerData(Game_Player player) { string save = string.Empty; // save groups foreach (Game_Group group in player.Deck.Groups) { for (int y = 0; y <= group.UnitIDs.GetUpperBound(1); y++) { for (int x = 0; x <= group.UnitIDs.GetUpperBound(0); x++) { string seperator = (x == 4 && y == 4 ? ";" : ","); save += group.UnitIDs[x, y].ToString() + seperator; } } } save += Environment.NewLine; // save scores for (int level = 1; level <= Global.NUMBER_OF_LEVELS; level++) save += player.GetLevelScore(level) + ","; save += Environment.NewLine; // save unlocked units for (int unitID = 0; unitID < 10; unitID++) if (player.IsUnitUnlocked(unitID)) save += unitID.ToString() + ","; Directory.CreateDirectory(SAVE_FOLDER_PATH); File.WriteAllText(PLAYER_SAVE_PATH, save); }