예제 #1
0
        public void XmlWriteTest()
        {
            Level level = new Level();

            new Platform(level, 5, 1, new Vector2(200, 1900));
            new Platform(level, 5, 1, new Vector2(500, 1840));
            //new Platform(level, 5, 1, new Vector2(200, 1760));
            //new Platform(level, 5, 1, new Vector2(200, 1680));
            //new Platform(level, 5, 1, new Vector2(200, 1600));
            //new Platform(level, 5, 1, new Vector2(500, 1520));
            //new Platform(level, 20, 5, new Vector2(600, 1440));
            //new Platform(level, 20, 23, new Vector2(700, 1540));
            //new Platform(level, 20, 23, new Vector2(1140, 1540));
            //new Platform(level, 1, 23, new Vector2(1140, 1200));
            level.FirstCheckpoint = new PlayerCheckpoint(level);
            new DeadlyPlatform(level, 2, 1, new Vector2(1100, 1980));

            new ColorPickup(level, Color.Yellow, new Vector2(1115, 1950));
            //level.Add(new ColorPickup(this, Color.Yellow, new Vector2(1115, 1970)));

            level.WriteToFile("level.xml");
        }
예제 #2
0
        public void OpenLevel()
        {
            string[] filePaths = System.IO.Directory.GetFiles("../../../../levels/", "*.xml");
            string totalList = "";
            string newFileName = "";
            int fileNumber = 0;

            newFileName = filePaths.Count() > 0 ? "0" : "LevelName";

            for (int i = 0; i < filePaths.Count(); i++) {
                filePaths[i] = Path.GetFileNameWithoutExtension(filePaths[i]);
                totalList += "\r\n" + i + ": " + filePaths[i];
            }

            newFileName = Interaction.InputBox("Enter the number from below or enter your own name for a new file:\r\n" + totalList, "Open Level", newFileName);

            if(int.TryParse(newFileName, out fileNumber)) {
                if(fileNumber >= 0 && fileNumber < filePaths.Count()) {
                    newFileName = filePaths[fileNumber];
                } else {
                    newFileName = "";
                }
            }

            if (newFileName == "") {
                Interaction.MsgBox("Level loading aborted", MsgBoxStyle.Critical, "Open Level");
                return;
            }

            _currentLevelName = newFileName;
            try {
                CurrentLevel = Level.LoadFromFile("../../../../levels/" + _currentLevelName + ".xml");
                CurrentLevel.Initialize();
            } catch (Exception) {
                Interaction.MsgBox("Level file '" + _currentLevelName + ".xml' not found!\r\n\r\nCreating new world...", MsgBoxStyle.Critical, "Open Level");
                CurrentLevel = new Level();
                CurrentLevel.Initialize();
            }
        }
예제 #3
0
 public void CreateNewLevel()
 {
     if (CurrentLevel == null)
         CurrentLevel = new Level();
 }