//Reads in SaveFile Personal Obtained Keys File. Then returns the list of keys back. private static SavedDataFile LoadInKeys(SavedDataFile sdf, string filename, string goldOrSilver) { //Variables List <string> Keys = new List <string>(); //Create list to hold the LevelKeyNames of the keys obtained. StreamReader sr = new StreamReader(filename); //Create a StreamReader. //Loop to read all lines and add the info to Keys list. while (!sr.EndOfStream) { string temp = sr.ReadLine(); Keys.Add(temp); } //Load in obtained keys. foreach (string str in Keys) { if (goldOrSilver == "gold") { sdf.SetObtainedGoldenKeys(WorldMapScreen.keyInventory.FindKeyAndSetObtainToTrue(goldOrSilver, str)); } else { sdf.SetObtainedSilverKeys(WorldMapScreen.keyInventory.FindKeyAndSetObtainToTrue(goldOrSilver, str)); } } //Closing Code sr.Close(); //Close sr return(sdf); //Return sdf object. }
//This is the master function For Loading Saved Data. public static SavedDataFile LoadSavedInformation(SavedDataFile sdf, int sdfNumber) { //Get TextFiles. string PO_TextFile = GetPlayerDataPath(sdfNumber); //Get Player Info txt file. string PGK_TextFile = GetPlayerGoldenKeysPath(sdfNumber); //Get Golden Keys txt file. string PSK_TextFile = GetPlayerSilverKeysPath(sdfNumber); //Get Silver Keys txt file. //Get Informations and return it to sdf. sdf = LoadOtherPlayerData(sdf, PO_TextFile); //Get main player data sdf = LoadInKeys(sdf, PGK_TextFile, "gold"); //Get acquired Golden Keys sdf = LoadInKeys(sdf, PSK_TextFile, "silver"); //Get acquired Silver Keys //Return sdf for use. return(sdf); }
//Public Master Function to Save Data public static void SaveFileInfo(SavedDataFile sdf) { // Writing data: string[] POtoken = new string[3]; POtoken[0] = sdf.GetSaveFileNumber().ToString(); //Set Save File Number to index 0 POtoken[1] = sdf.GetWhichCharacter().ToString(); //Set whichCharcter to index 1 POtoken[2] = sdf.GetLevelsUnlocked().ToString(); //Set levelsUnlocked to index 2 //Rewrite all lines with new data File.WriteAllLines(GetSaveFilePlayerInfoFilePath(sdf.GetSaveFileNumber()), POtoken); //Create a list names LevelObtainedKeys List <string> LevelObtainedKeys = new List <string>(); //Create string arrays to hold keys string[] PKGoldToken = new string[sdf.GetObtainedGoldenKeys().Count]; string[] PKSilverToken = new string[sdf.GetObtainedGoldenKeys().Count]; //Get the levelNames of all obtained keys in Golden Key List for (int i = 0; i < sdf.GetObtainedGoldenKeys().Count; i++) { if (sdf.GetObtainedGoldenKeys()[i].GetObtained() == true) { LevelObtainedKeys.Add(sdf.GetObtainedGoldenKeys()[i].GetKeyLevelName()); } } PKGoldToken = LevelObtainedKeys.ToArray(); //Change from list to array //Reset LevelObtainedKeys LevelObtainedKeys = new List <string>(); //Get the levelNames of all obtained keys in Silver Key List for (int i = 0; i < sdf.GetObtainedSilverKeys().Count; i++) { if (sdf.GetObtainedSilverKeys()[i].GetObtained() == true) { LevelObtainedKeys.Add(sdf.GetObtainedSilverKeys()[i].GetKeyLevelName()); } } PKSilverToken = LevelObtainedKeys.ToArray(); //Change from list to array //Rewrite all lines with new data File.WriteAllLines(GetSaveFilePlayerObtainedGoldenKeysFilePath(sdf.GetSaveFileNumber()), PKGoldToken); //Golden Key Info File.WriteAllLines(GetSaveFilePlayerObtainedSilverKeysFilePath(sdf.GetSaveFileNumber()), PKSilverToken); //Silver Key Info }
//This Function Loads The Battle and Player Variables into an object. private static SavedDataFile LoadOtherPlayerData(SavedDataFile sdf, string textFile) { //Variables reader = File.OpenText(textFile); //Open a txt file for reading. List <string> token = new List <string>(); //Create a token list to hold the info. //Loop to read all lines and add the info to token. while (!reader.EndOfStream) { string temp = reader.ReadLine(); token.Add(temp); } //Set info sdf.SetSaveFileNumber(int.Parse(token[0])); //Set Save File Number sdf.SetWhichCharacter(int.Parse(token[1])); //Set Which Character Selected sdf.SetLevelsUnlocked(int.Parse(token[2])); //Set Levels Unlocked //Closing code reader.Close(); //Close Reader return(sdf); //Return sdf object. }
private LevelEntrance LevelThirtyFour; // 3-12 #endregion #endregion #endregion //Constructor public WorldMapScreen(IGameScreenManager gameScreenManager) { //Set Manage and Command m_ScreenManager = gameScreenManager; m_command = new Command(m_ScreenManager); //Set To True Game1.isOnWorldMap = true; #region Load Saved Data //Load Game Data based on Game1.opener switch (Game1.opener) { case 1: SaveFile1 = LoadInformation.LoadSavedInformation(new SavedDataFile(1), 1); Game1.levelsUnlocked = SaveFile1.GetLevelsUnlocked(); GetPlayerTextures(SaveFile1.GetWhichCharacter()); if (SaveFile1.GetObtainedGoldenKeys().Count != 0) { keyInventory.SetGoldKeyList(SaveFile1.GetObtainedGoldenKeys()); } if (SaveFile1.GetObtainedSilverKeys().Count != 0) { keyInventory.SetSilverKeyList(SaveFile1.GetObtainedSilverKeys()); } break; case 2: SaveFile2 = LoadInformation.LoadSavedInformation(new SavedDataFile(2), 2); Game1.levelsUnlocked = SaveFile2.GetLevelsUnlocked(); GetPlayerTextures(SaveFile2.GetWhichCharacter()); if (SaveFile2.GetObtainedGoldenKeys().Count != 0) { keyInventory.SetGoldKeyList(SaveFile2.GetObtainedGoldenKeys()); } if (SaveFile2.GetObtainedSilverKeys().Count != 0) { keyInventory.SetSilverKeyList(SaveFile2.GetObtainedSilverKeys()); } break; case 3: SaveFile3 = LoadInformation.LoadSavedInformation(new SavedDataFile(3), 3); Game1.levelsUnlocked = SaveFile3.GetLevelsUnlocked(); GetPlayerTextures(SaveFile3.GetWhichCharacter()); if (SaveFile3.GetObtainedGoldenKeys().Count != 0) { keyInventory.SetGoldKeyList(SaveFile3.GetObtainedGoldenKeys()); } if (SaveFile3.GetObtainedSilverKeys().Count != 0) { keyInventory.SetSilverKeyList(SaveFile3.GetObtainedSilverKeys()); } break; default: break; } #endregion #region Timer Stuff //Set interval moveToNextLevel.Interval = 500; #endregion }