Пример #1
0
        public void SlowingObstacle_MouseUp(object sender, MouseEventArgs e)
        {
            modelEditor.slowingObstacle.Location = new System.Drawing.Point(10, 210);

            if ((mouseX) >= modelEditor.widthDragDropPanel && mouseX <= modelEditor.gamePanel.Width
                && mouseY >= modelEditor.gamePanel.Location.Y && mouseY <= modelEditor.gamePanel.Height)
            {
                String dialog = ShowDialog("SlowingObstacle", "Set properties for Slowing Obstacle");

                if (dialog != "")
                {
                    string[] returnValues = dialog.Split(new string[] { "|" }, StringSplitOptions.None);
                    SlowingObstacle sb = new SlowingObstacle(new Point(mouseX - modelEditor.widthDragDropPanel, mouseY), defaultSize, defaultSize);

                    if (returnValues[0] == "Slow")
                        sb.MovingSpeed = 0;
                    else if (returnValues[0] == "Moderate")
                        sb.MovingSpeed = 1;
                    else if (returnValues[0] == "Fast")
                        sb.MovingSpeed = 2;
                    else if (returnValues[0] == "Unmöglich")
                        sb.MovingSpeed = 3;

                    if (returnValues[1] == "Freeze the player")
                        sb.SlowingSpeed = 0;
                    else if (returnValues[1] == "Very slow")
                        sb.SlowingSpeed = 1;
                    else if (returnValues[1] == "Slow")
                        sb.SlowingSpeed = 2;
                    else if (returnValues[1] == "Normal")
                        sb.SlowingSpeed = 4;

                    if (returnValues[2] == "Unchecked")
                        sb.IsSmart = false;
                    else
                        sb.IsSmart = true;

                    gameObjects.Add(sb);
                    modelEditor.gamePanel.Invalidate();
                }
            }
        }
Пример #2
0
        public List<GameObject> getCleanGameObjects()
        {
            List<GameObject> returnList = new List<GameObject>();

            //Hardcoded start en eindpunt toevoegen aan level
            returnList.Add(new Checkpoint(new Point(750, 400), Resources.IconWIN, 80, 80, false));
            returnList.Add(new Checkpoint(new Point(5, -5), Resources.IconSP, 80, 80, true));

            foreach (GameObject gameObject in gameObjects)
            {
                if (gameObject is ExplodingObstacle)
                {
                    returnList.Add(new ExplodingObstacle(new Point(gameObject.Location.X, gameObject.Location.Y), gameObject.Height, gameObject.Width));
                }
                else if (gameObject is MovingExplodingObstacle)
                {
                    MovingExplodingObstacle castedGameObject = (MovingExplodingObstacle)gameObject;

                    MovingExplodingObstacle moe = new MovingExplodingObstacle(new Point(gameObject.Location.X, gameObject.Location.Y), gameObject.Height, gameObject.Width);
                    moe.MovingSpeed = castedGameObject.MovingSpeed;
                    moe.IsSmart = ((MovingExplodingObstacle)gameObject).IsSmart;

                    returnList.Add(moe);
                }
                else if (gameObject is StaticObstacle)
                {
                    returnList.Add(new StaticObstacle(new Point(gameObject.Location.X, gameObject.Location.Y), gameObject.Height, gameObject.Width));
                }
                else if (gameObject is SlowingObstacle)
                {
                    SlowingObstacle castedGameObject = (SlowingObstacle)gameObject;

                    SlowingObstacle slowingObstacle = new SlowingObstacle(new Point(gameObject.Location.X, gameObject.Location.Y), gameObject.Height, gameObject.Width);
                    slowingObstacle.MovingSpeed = castedGameObject.MovingSpeed;
                    slowingObstacle.SlowingSpeed = castedGameObject.SlowingSpeed;
                    slowingObstacle.IsSmart = ((SlowingObstacle)gameObject).IsSmart;

                    returnList.Add(slowingObstacle);
                }
            }
            return returnList;
        }
Пример #3
0
        //Funtie om XML bestand in te laden, daarna kan je de vastgelegde variablen in deze klasse gebruiken
        public bool ReadXML()
        {
            XDocument doc;
            try { doc = XDocument.Load(this.path); }
            catch { return false; }

            //Initieert de variablen
            gameHighscores = new List<GameHighscore>();
            gameObjects = new List<GameObject>();

            //Voert query uit op het XML document om de properties te laden in een var
            var lproperties = from r in doc.Descendants("properties")
                             select new
                             {
                                 Title = r.Element("title").Value,
                                 Difficulty = r.Element("difficulty").Value
                             };
            //Ditzelfde voor highscores
            var highscores = from r in doc.Descendants("highscore")
                            select new
                            {
                                Name = r.Element("name").Value,
                                DateTime = r.Element("datetime").Value,
                                //Score wordt direct geconverteert naar een int omdat deze ook zo wordt weggeschreven
                                Score = Int32.Parse(r.Element("score").Value),
                            };
            //en voor object
            var items = from r in doc.Descendants("object")
                        select new
                        {
                            Type = r.Element("type").Value,
                            //Directe conversie naar int omdat deze ook zo wordt weggeschreven
                            X = Int32.Parse(r.Element("x").Value),
                            Y = Int32.Parse(r.Element("y").Value),
                            Height = Int32.Parse(r.Element("height").Value),
                            Width = Int32.Parse(r.Element("width").Value),
                            //If statements voor dynamische gegevens in xml <object>
                            Movingspeed = (r.Element("movingspeed") != null) ? Int32.Parse(r.Element("movingspeed").Value): 0,
                            Slowdown = (r.Element("slowingspeed") != null) ? Int32.Parse(r.Element("slowingspeed").Value): 0,
                            Smart = (r.Element("smart") != null) ? bool.Parse(r.Element("smart").Value) : false,
                            Image = (r.Element("image") != null) ? r.Element("image").Value : ""
                       };
            //Voegt de gameproperties toe aan de variable gameProperties
            foreach (var property in lproperties)
            {
                gameProperties = new GameProperties(property.Title, property.Difficulty);
            }

            //Voegt alle highscores toe in een List
            highscores.OrderBy(o => o.Score);
            foreach (var highscore in highscores)
            {
                gameHighscores.Add(new GameHighscore(highscore.Name, highscore.DateTime, highscore.Score));
            }
            //Sorteert highscores op volgorde van behaalde score
            gameHighscores = gameHighscores.OrderBy(highscore => highscore.score).ToList();

            //Hardcoded start en eindpunt toevoegen aan level
            gameObjects.Add(new Checkpoint(new Point(750, 400), Resources.IconWIN, 80, 80, false));
            gameObjects.Add(new Checkpoint(new Point(5, -5), Resources.IconSP, 80, 80, true));

            //Voegt alle gameObjecten toe in een List
            foreach (var gameObject in items)
            {
                    switch (gameObject.Type)
                    {

                        case "ExplodingObstacle":
                            gameObjects.Add(new ExplodingObstacle(new Point(gameObject.X, gameObject.Y), gameObject.Height, gameObject.Width));
                        break;

                        case "MovingExplodingObstacle":
                            MovingExplodingObstacle moe = new MovingExplodingObstacle(new Point(gameObject.X, gameObject.Y), gameObject.Height, gameObject.Width);
                            moe.MovingSpeed = gameObject.Movingspeed;
                            moe.IsSmart = gameObject.Smart;
                            gameObjects.Add(moe);
                        break;

                        case "StaticObstacle":
                            gameObjects.Add(new StaticObstacle(new Point(gameObject.X, gameObject.Y), gameObject.Height, gameObject.Width));
                        break;

                        case "SlowingObstacle":
                            SlowingObstacle sb = new SlowingObstacle(new Point(gameObject.X, gameObject.Y), gameObject.Height, gameObject.Width);
                            sb.MovingSpeed = gameObject.Movingspeed;
                            sb.SlowingSpeed = gameObject.Slowdown;
                            sb.IsSmart = gameObject.Smart;
                            gameObjects.Add(sb);
                        break;
                }

            }
            return true;
        }
Пример #4
0
        private void ProcessObstacles()
        {
            ModelGame mg = (ModelGame)model;

            // We moeten een 2e array maken om door heen te loopen
            // Er is kans dat we de array door lopen en ook tegelijkertijd een explosie toevoegen
            // We voegen dan als het ware iets toe en lezen tegelijk, dit mag niet
            List <GameObject> safeListArray = new List <GameObject>(mg.GameObjects);

            // Loop door alle obstacles objecten en roep methode aan
            foreach (GameObject gameObject in safeListArray)
            {
                if (gameObject is MovingExplodingObstacle)
                {
                    MovingExplodingObstacle gameObstacle = (MovingExplodingObstacle)gameObject;
                    gameObstacle.ChasePlayer(mg.player);

                    if (gameObstacle.CollidesWith(mg.player))
                    {
                        mg.player.Location = new Point(0, 0);
                        mg.InitializeField();
                        mg.GameObjects.Add(new Explosion(gameObstacle.Location, 80, 80));
                    }
                }

                if (gameObject is SlowingObstacle)
                {
                    SlowingObstacle gameObstacle = (SlowingObstacle)gameObject;
                    gameObstacle.ChasePlayer(mg.player);

                    if (gameObstacle.CollidesWith(mg.player))
                    {
                        mg.player.Speed = mg.player.OriginalSpeed / 2;
                    }
                    else
                    {
                        mg.player.Speed = mg.player.OriginalSpeed;
                    }
                }

                if (gameObject is ExplodingObstacle)
                {
                    ExplodingObstacle gameObstacle = (ExplodingObstacle)gameObject;

                    if (gameObstacle.CollidesWith(mg.player))
                    {
                        mg.player.Location = new Point(0, 0);
                        mg.InitializeField();
                        mg.GameObjects.Add(new Explosion(gameObstacle.Location, 80, 80));
                    }
                }

                if (gameObject is StaticObstacle)
                {
                    StaticObstacle gameObstacle = (StaticObstacle)gameObject;

                    if (gameObstacle.CollidesWith(mg.player))
                    {
                        if (pressedUp)
                        {
                            mg.player.Location = new Point(mg.player.Location.X, mg.player.Location.Y + mg.player.Speed);
                        }
                        if (pressedDown)
                        {
                            mg.player.Location = new Point(mg.player.Location.X, mg.player.Location.Y - mg.player.Speed);
                        }
                        if (pressedLeft)
                        {
                            mg.player.Location = new Point(mg.player.Location.X + mg.player.Speed, mg.player.Location.Y);
                        }
                        if (pressedRight)
                        {
                            mg.player.Location = new Point(mg.player.Location.X - mg.player.Speed, mg.player.Location.Y);
                        }
                    }
                }

                // Check of we de explosie kunnen verwijderen
                if (gameObject is Explosion)
                {
                    Explosion explosion = (Explosion)gameObject;

                    DateTime nowDateTime       = DateTime.Now;
                    DateTime explosionDateTime = explosion.TimeStamp;

                    TimeSpan difference = nowDateTime - explosionDateTime;

                    // Verschil is 3 seconden, dus het bestaat al voor 3 seconden, verwijderen maar!
                    if (difference.TotalSeconds > 3)
                    {
                        mg.GameObjects.Remove(gameObject);
                    }
                }
            }
        }