Example #1
0
        public void TestXMLParser_Save()
        {
            GameProperties gameProperties = new GameProperties("Test Level", "easy");

            List<GameObject> gameObjects;
            Player player;
            BuildGameField(out gameObjects, out player);

            GameHighscore gameHighscore = new GameHighscore("Test Speler", DateTime.Now.ToString(), 900);

            XMLParser xmlParser = new XMLParser("unitTestXML.xml");

            if(xmlParser == null)
                Assert.Fail("NRE");

            xmlParser.gameHighscores.Add(gameHighscore);
            xmlParser.gameProperties = gameProperties;
            xmlParser.gameObjects = gameObjects;

            if (!xmlParser.WriteXML())
                Assert.Fail("Kan niet Write XML uitvoeren");
        }
 public void saveLevel_Click(object sender, EventArgs e)
 {
     if (level == null)
     {
         //Als nieuw level
         string dialog = showPropertyDialog("Set properties for Level");
         if (dialog != "")
         {
             string[] returnValues = dialog.Split(new string[] { "|" }, StringSplitOptions.None);
             string title = returnValues[0].ToString();
             string difficulty = returnValues[1].ToString();
             string file;
             if (System.Diagnostics.Debugger.IsAttached)
                 file = "../levels/" + title + ".xml";
             else
                 file = AppDomain.CurrentDomain.BaseDirectory + "/levels/" + title + ".xml";
             if (!File.Exists(file)) {
                 level = new XMLParser(file);
                 GameProperties gameProperties = new GameProperties(title, difficulty);
                 level.gameProperties = gameProperties;
                 level.gameObjects = gameObjects;
                 level.WriteXML();
                 modelEditor.gamePanel.Invalidate();
             }
             else
                 MessageBox.Show("Sorry, '" + title + "' already exist. Try again with another level name.");
         }
     }
     else
     {
         // Als Edit level
         level.gameObjects = gameObjects;
         level.WriteXML();
         MessageBox.Show("Saved changes to " + level.gameProperties.title);
     }
 }
Example #3
0
        public void TestXMLParser_Load()
        {
            GameProperties gameProperties = new GameProperties("Test Level", "easy");

            List<GameObject> gameObjects;
            Player player;
            BuildGameField(out gameObjects, out player);

            GameHighscore gameHighscore = new GameHighscore("Test Speler", DateTime.Now.ToString(), 900);

            XMLParser xmlParser = new XMLParser("unitTestXML.xml");

            if (xmlParser == null)
                Assert.Fail("NRE");

            xmlParser.gameHighscores.Add(gameHighscore);
            xmlParser.gameProperties = gameProperties;
            xmlParser.gameObjects = gameObjects;

            if (!xmlParser.WriteXML())
                Assert.Fail("Kan niet Write XML uitvoeren");

            // Reset XML
            xmlParser = null;
            xmlParser = new XMLParser("unitTestXML.xml");

            if(!xmlParser.ReadXML())
                Assert.Fail("Kan niet Load XML uitvoeren");

            Assert.AreEqual(gameProperties, xmlParser.gameProperties, "GameProperties not equal");

            // We hebben checkpoints gehardcode, dus nu even verwijderen
            xmlParser.gameObjects.RemoveAt(0);
            xmlParser.gameObjects.RemoveAt(1);
            Assert.AreEqual(gameObjects.Count, xmlParser.gameObjects.Count, "GameObjects not equal");
        }