public override void ControlsInit(Form gameWindow) { alignPanel = new Panel(); alignPanel.AutoSize = true; levels = new ListBox(); levels.Size = new System.Drawing.Size(200, 475); levels.Location = new System.Drawing.Point(0, 40); string[] fileEntries = Directory.GetFiles("../levels/"); foreach (string file in fileEntries) { XMLParser xml = new XMLParser(file); xml.ReadXML(); levels.Items.Add(xml.gameProperties.title); } labelLevels = new Label(); labelLevels.Text = "Levels"; labelLevels.Font = new Font("Arial", 20); labelLevels.Location = new System.Drawing.Point(0, 0); labelLevels.Size = new System.Drawing.Size(200, 30); labelLevels.TextAlign = ContentAlignment.MiddleCenter; goBack = new Button(); goBack.Size = new System.Drawing.Size(200, 25); goBack.Location = new System.Drawing.Point(0, 525); goBack.Text = "Go Back"; goBack.Click += new EventHandler(highscoresController.goBack_Click); gameWindow.Controls.Add(alignPanel); alignPanel.Controls.Add(labelLevels); alignPanel.Controls.Add(goBack); alignPanel.Controls.Add(levels); alignPanel.Location = new Point( (gameWindow.Width / 2 - alignPanel.Size.Width / 2), (gameWindow.Height / 2 - alignPanel.Size.Height / 2)); alignPanel.Anchor = AnchorStyles.None; }
public override void ControlsInit(Form gameWindow) { alignPanel = new Panel(); alignPanel.AutoSize = true; gamePanel = new Panel(); gamePanel.Location = new System.Drawing.Point(210, 40); gamePanel.Size = new System.Drawing.Size(845, 475); gamePanel.BackColor = Color.DarkGray; levels = new ListBox(); levels.Size = new System.Drawing.Size(200, 475); levels.Location = new System.Drawing.Point(0, 40); string[] fileEntries = Directory.GetFiles("../levels/"); foreach (string file in fileEntries) { XMLParser xml = new XMLParser(file); xml.ReadXML(); levels.Items.Add(xml.gameProperties.title); } labelLevels = new Label(); labelLevels.Text = "Levels"; labelLevels.Font = new Font("Arial", 20); labelLevels.Location = new System.Drawing.Point(0, 0); labelLevels.Size = new System.Drawing.Size(200, 30); labelLevels.TextAlign = ContentAlignment.MiddleCenter; labelLevelPreview = new Label(); labelLevelPreview.Text = "Level Preview"; labelLevelPreview.Font = new Font("Arial", 20); labelLevelPreview.Location = new System.Drawing.Point(210, 0); labelLevelPreview.Size = new System.Drawing.Size(845, 30); labelLevelPreview.TextAlign = ContentAlignment.MiddleCenter; goBack = new Button(); goBack.Size = new System.Drawing.Size(200, 25); goBack.Location = new System.Drawing.Point(0, 525); goBack.Text = "Go Back"; goBack.Click += new EventHandler(levelSelectController.goBack_Click); playLevel = new Button(); playLevel.Size = new System.Drawing.Size(845, 25); playLevel.Location = new System.Drawing.Point(210, 525); playLevel.Text = "Play Level"; playLevel.Click += new EventHandler(levelSelectController.goBack_Click); gameWindow.Controls.Add(alignPanel); alignPanel.Controls.Add(labelLevels); alignPanel.Controls.Add(labelLevelPreview); alignPanel.Controls.Add(goBack); alignPanel.Controls.Add(playLevel); alignPanel.Controls.Add(levels); alignPanel.Controls.Add(gamePanel); alignPanel.Location = new Point( (gameWindow.Width / 2 - alignPanel.Size.Width / 2), (gameWindow.Height / 2 - alignPanel.Size.Height / 2)); alignPanel.Anchor = AnchorStyles.None; }
//Laad alle levels en stopt deze in de static property Levels //Belangerijk om deze eerst aan te roepen voordat je de static property gebruikt via XMLParser.Levels public static bool LoadAllLevels() { Levels.Clear(); string dirPath = ""; if (System.Diagnostics.Debugger.IsAttached) { dirPath = "../levels/"; } else { dirPath = AppDomain.CurrentDomain.BaseDirectory + "/levels/"; } string[] fileEntries = Directory.GetFiles(dirPath); try { foreach (string file in fileEntries) { if (File.Exists(file)) { if (isXML(file)) { XMLParser xml = new XMLParser(file); xml.ReadXML(); Levels.Add(xml); //Ingeladen gegevens opslaan in lokale List voor hergebruik } } } return true; } catch { return false; } }
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"); }