Ejemplo n.º 1
0
        public void GetPlace()
        {
            int i = 0;
            List<GameHighscore> tempHighscores = new List<GameHighscore>();

            // Vullen van highscorelijst
            foreach (GameHighscore highscore in ModelGame.level.gameHighscores)
            {
                tempHighscores.Add(highscore);
            }
            GameHighscore tempHighscore = new GameHighscore("tempHighscore", DateTime.Now.ToString(), score);
            tempHighscores.Add(tempHighscore);
            tempHighscores = tempHighscores.OrderBy(highscore => highscore.score).ToList();

            i = 0;
            foreach (GameHighscore highscore in tempHighscores)
            {
                i++;
                if (highscore.Equals(tempHighscore))
                {
                    place = i;
                }
            }
        }
Ejemplo n.º 2
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");
        }
Ejemplo n.º 3
0
        public bool AddHighscore(GameHighscore highscore)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(this.path);

            XmlNode root = doc.DocumentElement;

            if (doc.SelectSingleNode("//highscores") == null)
            {
                XmlElement highScoresElement = doc.CreateElement("highscores");
                root.AppendChild(highScoresElement);
            }

            XmlNode highscores = doc.SelectSingleNode("//highscores");

            XmlElement highScoreElement = doc.CreateElement("highscore");

            XmlElement nameElement = doc.CreateElement("name");
            nameElement.InnerText = highscore.name;

            XmlElement datetimeElement = doc.CreateElement("datetime");
            datetimeElement.InnerText = highscore.dateTime.ToString();

            XmlElement scoreElement = doc.CreateElement("score");
            scoreElement.InnerText = highscore.score.ToString();

            highScoreElement.AppendChild(nameElement);
            highScoreElement.AppendChild(datetimeElement);
            highScoreElement.AppendChild(scoreElement);

            //Add the node to the document.
            highscores.AppendChild(highScoreElement);
            try {
                doc.Save(this.path);
                return true;
            }
            catch
            {
                return false;
            }
        }
Ejemplo n.º 4
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");
        }