public static List <LevelBodyPart> LoadAllParts() { List <LevelBodyPart> parts = new List <LevelBodyPart>(); string levelDir = "levels/"; DirectoryInfo dir = new DirectoryInfo(levelDir); if (!dir.Exists) { throw new DirectoryNotFoundException(); } FileInfo[] files = dir.GetFiles("*.map"); foreach (FileInfo file in files) { LevelBodyPart bodyPart = new LevelBodyPart(); using (StreamReader readFileStream = new StreamReader(file.FullName)) { string line = readFileStream.ReadLine(); string[] words = line.Split(' '); for (int i = 0; i < words.Count(); i++) { if (words[i] == "Position") { i++; foreach (var part in Enum.GetValues(typeof(BodyPartType))) { if (Enum.GetName(typeof(BodyPartType), part).Equals(words[i], StringComparison.CurrentCultureIgnoreCase)) { bodyPart.Position = (BodyPartType)part; break; } } } else if (words[i] == "LevelNumber") { bodyPart.LevelNumber = int.Parse(words[++i]); } } } FileInfo[] mapFiles = dir.GetFiles(Path.GetFileNameWithoutExtension(file.Name) + '*' + ".png"); foreach (var map in mapFiles) { bodyPart.AddLevel(map.FullName); } parts.Add(bodyPart); } return(parts); }
public static List<LevelBodyPart> LoadAllParts() { List<LevelBodyPart> parts = new List<LevelBodyPart>(); string levelDir = "levels/"; DirectoryInfo dir = new DirectoryInfo(levelDir); if (!dir.Exists) throw new DirectoryNotFoundException(); FileInfo[] files = dir.GetFiles("*.map"); foreach (FileInfo file in files) { LevelBodyPart bodyPart = new LevelBodyPart(); using (StreamReader readFileStream = new StreamReader(file.FullName)) { string line = readFileStream.ReadLine(); string[] words = line.Split(' '); for (int i = 0; i < words.Count(); i++) { if (words[i] == "Position") { i++; foreach (var part in Enum.GetValues(typeof(BodyPartType))) { if (Enum.GetName(typeof(BodyPartType), part).Equals(words[i], StringComparison.CurrentCultureIgnoreCase)) { bodyPart.Position = (BodyPartType)part; break; } } } else if (words[i] == "LevelNumber") { bodyPart.LevelNumber = int.Parse(words[++i]); } } } FileInfo[] mapFiles = dir.GetFiles(Path.GetFileNameWithoutExtension(file.Name) + '*' + ".png"); foreach (var map in mapFiles) { bodyPart.AddLevel(map.FullName); } parts.Add(bodyPart); } return parts; }
public virtual void OnChange(Object o) { _camera.ResetCamera(); _camera.Zoom = START_ZOOM; _camera.Position = Utils.GetScreenCenter(_spriteBatch.GraphicsDevice); _camera.Jump2Target(); _chosenBodyPart = ChooseNextBodyPart(); ResetTimers(); }