예제 #1
0
        public void level_Select(object sender, EventArgs e)
        {
            ListBox listBoxLevels = (ListBox)sender;
            currentSelectedLevel = (XMLParser)listBoxLevels.SelectedItem;

            modelEditorSelect.gamePanel.Invalidate(); // refresh
        }
예제 #2
0
        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;
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
 public void testLevel_Click(object sender, EventArgs e)
 {
     // Maakt nieuw level aan
     XMLParser tempLevel = new XMLParser();
     tempLevel.gameObjects = gameObjects;
     ModelGame.level = tempLevel;
     ControllerGame.editor = true; // Laat Game controller weten dat we aan het testen zijn
     gameWindow.setController(ScreenStates.game);
 }
예제 #5
0
 public void goBack_Click(object sender, EventArgs e)
 {
     gameWindow.setController(ScreenStates.editorSelect);
     // Opschonen
     level = null;
     gameObjects.Clear();
 }
예제 #6
0
        public override void RunController()
        {
            base.RunController();

            if (ModelGame.level != null && level != null)
            { // Als bestaand level nog niet opgeslagen is maar terugkomt van de test
                gameObjects = ModelGame.level.getCleanGameObjects();
            }
            else
            {
                level = ModelEditor.level;
                if (level != null)
                { // Bestaand level bewerken
                    gameObjects = level.getCleanGameObjects();
                }
                else
                { // Niew level make
                    gameObjects = new List<GameObject>();
                }
            }

            ModelGame.level = null;
            modelEditor.gamePanel.Invalidate();
        }
예제 #7
0
        public void level_Select(object sender, EventArgs e)
        {
            ListBox listBoxLevels = (ListBox)sender;
            currentSelectedLevel = (XMLParser)listBoxLevels.SelectedItem;

            modelHighscores.listBoxHighscores.Items.Clear();

            int i = 0;
            // Laat alle highscores zien
            foreach (GameHighscore highscore in currentSelectedLevel.gameHighscores)
            {
                i++;
                char[] a = highscore.name.ToCharArray();
                a[0] = char.ToUpper(a[0]);

                string highscoreText = i + ". " + new string(a);
                if (a.Length < 5) // Extra spaties bij kleinere namen
                    highscoreText += "    ";
                if (a.Length < 6)
                    highscoreText += "    ";
                highscoreText += "\tscore: " + highscore.score;
                if (highscore.score.ToString().Length < 3) // Extra spaties als score uit 2 of minder cijfers bestaat
                    highscoreText += "  ";
                highscoreText += "    " + highscore.dateTime.ToString("dd-MM-yy H:mm");
                modelHighscores.listBoxHighscores.Items.Add(highscoreText);
                if (i == 0)
                {
                    listBoxLevels.SetSelected(0, true);
                }
            }
        }
예제 #8
0
        //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; }
        }
예제 #9
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");
        }
예제 #10
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");
        }
예제 #11
0
        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;
        }