private void saveLevels_FileOk(object sender, CancelEventArgs e) { String filepath = saveLevels.FileName; if (!filepath.Contains(".txt")) { filepath += ".txt"; } using (StreamWriter sw = new StreamWriter(filepath)) { List <Platform> platforms = editor.getPlatforms(); List <Sentry> sentries = editor.getSentries(); List <Player> players = editor.getPlayers(); sw.WriteLine(platforms.Count + " " + sentries.Count); sw.WriteLine(editor.getName()); foreach (Platform p in platforms) { sw.WriteLine(p.getLocation().X + " " + p.getLocation().Y + " " + p.getWidth()); } sw.WriteLine(editor.getNote()); foreach (Sentry s in sentries) { sw.WriteLine(s.getType() + " " + (s.getDirection() * s.getSpeed()) + " " + s.getSecondary() + " " + platforms.IndexOf(s.getPlatform())); } } }
public static Level fromEditor(EditorLevel editor, main main) { List <Player> playersCopy = new List <Player>(); foreach (Player p in editor.getPlayers()) { playersCopy.Add(new Player()); } Player[] players = playersCopy.ToArray(); List <Platform> ps = new List <Platform>(); foreach (Platform p in editor.getPlatforms()) { ps.Add(new Platform(p.getLocation(), p.getWidth())); } Platform[] platforms = ps.ToArray(); List <Sentry> ss = new List <Sentry>(); foreach (Sentry s in editor.getSentries()) { ss.Add(new Sentry(s.getType(), s.getDirection() * s.getSpeed(), s.getSecondary())); } Sentry[] sentries = ss.ToArray(); int[] key = new int[sentries.Length]; for (int i = 0; i < key.Length; i++) { key[i] = editor.getPlatforms().IndexOf( editor.getSentries().ElementAt(i).getPlatform()); } return(new Level(players, platforms, sentries, key, main.getSettings().getFollowMode(), main, editor.name, editor.note)); }