コード例 #1
0
 public Image DrawLine(Node previousLocation, Node currentLocation, Color color, Image image)
 {
     Pen pen = new Pen(color);
     Graphics gr = Graphics.FromImage(image);
     gr.DrawLine(pen, previousLocation.Location, currentLocation.Location);
     return image;
 }
コード例 #2
0
        private List<Node> CalculatePossibleNextLocationsNorthWest(Node currentLocation, int speed)
        {
            List<Node> possibleNextLocations = this.GetPossibleNextLocationsTemplate();

            if (speed == 1)
            {
                /*
                 * Calculate "middle middle" first. As it's easier to calculate other locations
                 * based on the middle Node.
                 */

                /*
                 * Now calculate every other Node.
                 */
                // upper left
                int distance1 = speed * this.FieldSize;
                int x1 = currentLocation.Location.X - distance1;
                int y1 = currentLocation.Location.Y - distance1;
                Point location1 = new Point(x1, y1);
                possibleNextLocations[0] = new Node(this.Hitbox, location1);

                // upper middle
                int distance2 = speed * this.FieldSize;
                int x2 = currentLocation.Location.X - distance2 + this.FieldSize;
                int y2 = currentLocation.Location.Y - distance2;
                Point location2 = new Point(x2, y2);
                possibleNextLocations[1] = new Node(this.Hitbox, location2);

                // middle left
                int distance4 = speed * this.FieldSize;
                int x4 = currentLocation.Location.X - distance4;
                int y4 = currentLocation.Location.Y - distance4 + this.FieldSize;
                Point location4 = new Point(x4, y4);
                possibleNextLocations[3] = new Node(this.Hitbox, location4);

                // middle middle
                Point location5 = new Point(-99, -99);
                Node node5 = new Node(this.Hitbox, location5);

                // middle right
                int distance6 = speed * this.FieldSize;
                int x6 = -99;
                int y6 = -99;
                Point location6 = new Point(x6, y6);
                possibleNextLocations[5] = new Node(this.Hitbox, location6);
            }
            else
            {
                /*
                 * Calculate "middle middle" first. As it's easier to calculate other locations
                 * based on the middle Node.
                 */

                /*
                 * Now calculate every other Node.
                 */
                // upper left
                int distance1 = (speed + 1) * this.FieldSize;
                int x1 = currentLocation.Location.X - distance1;
                int y1 = currentLocation.Location.Y - distance1;
                Point location1 = new Point(x1, y1);
                possibleNextLocations[0] = new Node(this.Hitbox, location1);

                // upper middle
                int distance2 = (speed + 1) * this.FieldSize;
                int x2 = currentLocation.Location.X - distance2 + this.FieldSize;
                int y2 = currentLocation.Location.Y - distance2;
                Point location2 = new Point(x2, y2);
                possibleNextLocations[1] = new Node(this.Hitbox, location2);

                // upper right
                int distance3 = (speed + 1) * this.FieldSize;
                int x3 = currentLocation.Location.X - distance3 + this.FieldSize + this.FieldSize;
                int y3 = currentLocation.Location.Y - distance3;
                Point location3 = new Point(x3, y3);
                possibleNextLocations[2] = new Node(this.Hitbox, location3);

                // middle left
                int distance4 = (speed + 1) * this.FieldSize;
                int x4 = currentLocation.Location.X - distance4;
                int y4 = currentLocation.Location.Y - distance4 + this.FieldSize;
                Point location4 = new Point(x4, y4);
                possibleNextLocations[3] = new Node(this.Hitbox, location4);

                // middle middle
                int distance5 = (speed + 1) * this.FieldSize;
                int x5 = currentLocation.Location.X - distance5 + this.FieldSize;
                int y5 = currentLocation.Location.Y - distance5 + this.FieldSize;
                Point location5 = new Point(x5, y5);
                possibleNextLocations[4] = new Node(this.Hitbox, location5);

                // middle right
                int distance6 = (speed + 1) * this.FieldSize;
                int x6 = currentLocation.Location.X - distance6 + this.FieldSize + this.FieldSize;
                int y6 = currentLocation.Location.Y - distance6 + this.FieldSize;
                Point location6 = new Point(x6, y6);
                possibleNextLocations[5] = new Node(this.Hitbox, location6);

                // lower left
                int distance7 = (speed + 1) * this.FieldSize;
                int x7 = currentLocation.Location.X - distance7;
                int y7 = currentLocation.Location.Y - distance7 + this.FieldSize + this.FieldSize;
                Point location7 = new Point(x7, y7);
                possibleNextLocations[6] = new Node(this.Hitbox, location7);

                // lower middle
                int distance8 = (speed + 1) * this.FieldSize;
                int x8 = currentLocation.Location.X - distance8 + this.FieldSize;
                int y8 = currentLocation.Location.Y - distance8 + this.FieldSize + this.FieldSize;
                Point location8 = new Point(x8, y8);
                possibleNextLocations[7] = new Node(this.Hitbox, location8);

                // lower right
                int distance9 = (speed - 1) * this.FieldSize;
                int x9 = currentLocation.Location.X - distance9;
                int y9 = currentLocation.Location.Y - distance9;
                Point location9 = new Point(x9, y9);
                possibleNextLocations[8] = new Node(this.Hitbox, location9);
            }

            return possibleNextLocations;
        }
コード例 #3
0
 protected void SetRoundFinishedPositionsFromXml()
 {
     this.RoundFinishedPositions = new BindingList<Node>();
     IEnumerable<XElement> elements = from el in this.XDocument.Element("map").Element("roundFinishedPositions").Elements() select el;
     foreach (XElement el in elements)
     {
         String sPositionX = el.Element("x").Value;
         String sPositionY = el.Element("y").Value;
         int iPositionX = 0;
         int iPositionY = 0;
         Int32.TryParse(sPositionX, out iPositionX);
         Int32.TryParse(sPositionY, out iPositionY);
         Point coordinate = new Point(iPositionX, iPositionY);
         Node node = new Node(this.Hitbox, coordinate);
         this.RoundFinishedPositions.Add(node);
     }
 }
コード例 #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="currentLocation"></param>
        /// <param name="carDirection"></param>
        /// <param name="speed"></param>
        /// <returns></returns>
        /// TODO Consider promoting this region to an own utility class.
        public List<Node> CalculatePossibleNextLocations(Node currentLocation, String carDirection, int speed)
        {
            List<Node> possibleNextLocations = null;

            // Calculates car directions. NOTE: Forbidden and round finished nodes are considered later.
            switch (carDirection)
            {
                case "NorthWest":
                    possibleNextLocations = this.CalculatePossibleNextLocationsNorthWest(currentLocation, speed);
                    break;

                case "North":
                    possibleNextLocations = this.CalculatePossibleNextLocationsNorth(currentLocation, speed);
                    break;

                case "NorthEast":
                    possibleNextLocations = this.CalculatePossibleNextLocationsNorthEast(currentLocation, speed);
                    break;

                case "East":
                    possibleNextLocations = this.CalculatePossibleNextLocationsEast(currentLocation, speed);
                    break;

                case "SouthEast":
                    possibleNextLocations = this.CalculatePossibleNextLocationsSouthEast(currentLocation, speed);
                    break;

                case "South":
                    possibleNextLocations = this.CalculatePossibleNextLocationsSouth(currentLocation, speed);
                    break;

                case "SouthWest":
                    possibleNextLocations = this.CalculatePossibleNextLocationsSouthWest(currentLocation, speed);
                    break;

                case "West":
                    possibleNextLocations = this.CalculatePossibleNextLocationsWest(currentLocation, speed);
                    break;

                default:
                    throw new Exception(String.Format("Unknown car direction in CalculatePossibleNextLocations-Method ({0}).", carDirection));
            }

            // Consider forbidden positions
            for(int i = 0; i < possibleNextLocations.Count; i++)
            {
                foreach(Node forbiddenPosition in this.ForbiddenPositions)
                {
                    if (possibleNextLocations[i].IsEqual(forbiddenPosition))
                    {
                        possibleNextLocations[i] = new Node(this.Hitbox, new Point(-99, -99));
                        break;
                    }
                }
                //      TODO OR would cross a forbiddenZone
                //          THEN possibleNextLocations[i] = new Node(this.Hitbox, new Point(-99, -99));

            }

            return possibleNextLocations;
        }
コード例 #5
0
        private List<Node> CalculatePossibleNextLocationsSouth(Node currentLocation, int speed)
        {
            List<Node> possibleNextLocations = this.GetPossibleNextLocationsTemplate();

            if (speed == 1)
            {
                /*
                 * Calculate "middle middle" first. As it's easier to calculate other locations
                 * based on the middle Node.
                 */

                /*
                 * Now calculate every other Node.
                 */
                // lower left
                int distance7 = speed * this.FieldSize;
                int x7 = currentLocation.Location.X - distance7;
                int y7 = currentLocation.Location.Y + distance7;
                Point location7 = new Point(x7, y7);
                possibleNextLocations[6] = new Node(this.Hitbox, location7);

                // lower middle
                int distance8 = speed * this.FieldSize;
                int x8 = currentLocation.Location.X;
                int y8 = currentLocation.Location.Y + distance8;
                Point location8 = new Point(x8, y8);
                possibleNextLocations[7] = new Node(this.Hitbox, location8);

                // lower right
                int distance9 = speed * this.FieldSize;
                int x9 = currentLocation.Location.X + distance9;
                int y9 = currentLocation.Location.Y + distance9;
                Point location9 = new Point(x9, y9);
                possibleNextLocations[8] = new Node(this.Hitbox, location9);
            }
            else
            {
                /*
                 * Calculate "middle middle" first. As it's easier to calculate other locations
                 * based on the middle Node.
                 */
                int distance5 = speed * this.FieldSize;
                int x5 = currentLocation.Location.X;
                int y5 = currentLocation.Location.Y + distance5;
                Point location5 = new Point(x5, y5);
                possibleNextLocations[4] = new Node(this.Hitbox, location5);

                /*
                 * Now calculate every other Node.
                 */
                // upper left
                int x1 = location5.X - this.FieldSize;
                int y1 = location5.Y - this.FieldSize;
                Point location1 = new Point(x1, y1);
                possibleNextLocations[0] = new Node(this.Hitbox, location1);

                // upper middle
                int x2 = location5.X;
                int y2 = location5.Y - this.FieldSize;
                Point location2 = new Point(x2, y2);
                possibleNextLocations[1] = new Node(this.Hitbox, location2);

                // upper right
                int x3 = location5.X + this.FieldSize;
                int y3 = location5.Y - this.FieldSize;
                Point location3 = new Point(x3, y3);
                possibleNextLocations[2] = new Node(this.Hitbox, location3);

                // middle left
                int x4 = location5.X - this.FieldSize;
                int y4 = location5.Y;
                Point location4 = new Point(x4, y4);
                possibleNextLocations[3] = new Node(this.Hitbox, location4);

                // middle middle (calculated in the beginning already)

                // middle right
                int x6 = location5.X + this.FieldSize;
                int y6 = location5.Y;
                Point location6 = new Point(x6, y6);
                possibleNextLocations[5] = new Node(this.Hitbox, location6);

                // lower left
                int x7 = location5.X - this.FieldSize;
                int y7 = location5.Y + this.FieldSize;
                Point location7 = new Point(x7, y7);
                possibleNextLocations[6] = new Node(this.Hitbox, location7);

                // lower middle
                int x8 = location5.X;
                int y8 = location5.Y + this.FieldSize;
                Point location8 = new Point(x8, y8);
                possibleNextLocations[7] = new Node(this.Hitbox, location8);

                // lower right
                int x9 = location5.X + this.FieldSize;
                int y9 = location5.Y + this.FieldSize;
                Point location9 = new Point(x9, y9);
                possibleNextLocations[8] = new Node(this.Hitbox, location9);
            }

            return possibleNextLocations;
        }
コード例 #6
0
 /// <summary>
 /// Compares two nodes with each other using the location.
 /// </summary>
 /// <param name="compareNode"></param>
 /// <returns>True if nodes are equal (the location).</returns>
 public bool IsEqual(Node compareNode)
 {
     return (this.Location.X == compareNode.Location.X && this.Location.Y == compareNode.Location.Y);
 }
コード例 #7
0
 private void CalculateEveryNode()
 {
     for (int x = 0; x < this.Image.Width; x += this.Fieldsize)
     {
         for (int y = 0; y < this.Image.Height; y += this.Fieldsize)
         {
             Point location = new Point(x, y);
             Node node = new Node(this.hitbox, location);
             this.EveryNode.Add(node);
         }
     }
 }
コード例 #8
0
 internal void AddForbiddenPositions(Node currentNode)
 {
     this.ForbiddenPositions.Add(currentNode);
 }
コード例 #9
0
 internal void AddCarStartPosition(Node currentNode)
 {
     this.CarStartPositions.Add(currentNode);
 }
コード例 #10
0
 internal void AddRoundFinishedPositionn(Node currentNode)
 {
     this.RoundFinishedPositions.Add(currentNode);
 }