示例#1
0
        /// <summary>
        /// Draw line borders for cities
        /// </summary>
        /// <param name="g">Graphics device for main panel</param>
        /// <param name="city_to_process">City flag to process, 1 or 2</param>
        private void DrawBorders(ref Graphics g, byte city_to_process)
        {
            // temp edge used for ArrayList.Contains() call
            ArrayList points = new ArrayList();
            CityEdge containsEdge = new CityEdge(0, 0, 0);
            CityEdge tempEdge = new CityEdge(0, 0, 0);
            int cityEdgeCount = (city_to_process == 1) ? city1EdgeCount : city2EdgeCount;
            int tempindex = 0;
            Point[] pointarray;
            CityEdge currentEdge = new CityEdge(-2,-2, city_to_process);
            tempindex = BorderEdges.IndexOf(currentEdge);

            if (tempindex >= 0)
            {
                currentEdge = (CityEdge)BorderEdges[tempindex];
                tempEdge.cityflag = city_to_process;
                points.Add(new Point(currentEdge.x, currentEdge.y));
                #region City Border Search
                for (int x = 0; x < cityEdgeCount; x++)
                {
                    // Search x y-1, x+1 y-1, x+1 y, x+1 y+1, x y+1 (from noon to 6)
                    tempEdge.x = currentEdge.x;
                    tempEdge.y = currentEdge.y - 1;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }

                    tempEdge.x = currentEdge.x + 1;
                    tempEdge.y = currentEdge.y - 1;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x + 1;
                    tempEdge.y = currentEdge.y;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x + 1;
                    tempEdge.y = currentEdge.y + 1;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x;
                    tempEdge.y = currentEdge.y + 1;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    // search from 6 to 12
                    // x-1 y+1, x-1 y, x-1 y-1
                    tempEdge.x = currentEdge.x - 1;
                    tempEdge.y = currentEdge.y + 1;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x - 1;
                    tempEdge.y = currentEdge.y;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x - 1;
                    tempEdge.y = currentEdge.y - 1;
                    tempindex = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                }
                #endregion
            }

            // draw city border
            if (points.Count > 0)
            {
                Pen cityPen = new Pen(Color.Red, 1);
                cityPen.Color = (city_to_process == 2) ? Color.Yellow : Color.Red;
                cityPen.LineJoin = LineJoin.Round;
                pointarray = new Point[points.Count];
                for (int x = 0; x < points.Count; x++)
                {
                    pointarray[x] = (Point)points[x];
                    pointarray[x].X = pointarray[x].X * 20 + 10;
                    pointarray[x].Y = pointarray[x].Y * 20 + 10;
                }
                g.DrawCurve(cityPen, pointarray, 0.9f);
                cityPen.Dispose();
            }
            points.Clear();
        }
        /// <summary>
        /// Draw line borders for cities
        /// </summary>
        /// <param name="g">Graphics device for main panel</param>
        /// <param name="city_to_process">City flag to process, 1 or 2</param>
        private void DrawBorders(ref Graphics g, byte city_to_process)
        {
            // temp edge used for ArrayList.Contains() call
            ArrayList points        = new ArrayList();
            CityEdge  containsEdge  = new CityEdge(0, 0, 0);
            CityEdge  tempEdge      = new CityEdge(0, 0, 0);
            int       cityEdgeCount = (city_to_process == 1) ? city1EdgeCount : city2EdgeCount;
            int       tempindex     = 0;

            Point[]  pointarray;
            CityEdge currentEdge = new CityEdge(-2, -2, city_to_process);

            tempindex = BorderEdges.IndexOf(currentEdge);

            if (tempindex >= 0)
            {
                currentEdge       = (CityEdge)BorderEdges[tempindex];
                tempEdge.cityflag = city_to_process;
                points.Add(new Point(currentEdge.x, currentEdge.y));
                #region City Border Search
                for (int x = 0; x < cityEdgeCount; x++)
                {
                    // Search x y-1, x+1 y-1, x+1 y, x+1 y+1, x y+1 (from noon to 6)
                    tempEdge.x = currentEdge.x;
                    tempEdge.y = currentEdge.y - 1;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }

                    tempEdge.x = currentEdge.x + 1;
                    tempEdge.y = currentEdge.y - 1;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x + 1;
                    tempEdge.y = currentEdge.y;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x + 1;
                    tempEdge.y = currentEdge.y + 1;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x;
                    tempEdge.y = currentEdge.y + 1;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    // search from 6 to 12
                    // x-1 y+1, x-1 y, x-1 y-1
                    tempEdge.x = currentEdge.x - 1;
                    tempEdge.y = currentEdge.y + 1;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x - 1;
                    tempEdge.y = currentEdge.y;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                    tempEdge.x = currentEdge.x - 1;
                    tempEdge.y = currentEdge.y - 1;
                    tempindex  = BorderEdges.IndexOf((CityEdge)tempEdge);
                    if (tempindex >= 0)
                    {
                        tempEdge = (CityEdge)BorderEdges[tempindex];
                        if (!tempEdge.processed)
                        {
                            tempEdge.processed     = true;
                            BorderEdges[tempindex] = tempEdge;
                            points.Add(new Point(tempEdge.x, tempEdge.y));
                            currentEdge = tempEdge;
                            continue;
                        }
                    }
                }
                #endregion
            }

            // draw city border
            if (points.Count > 0)
            {
                Pen cityPen = new Pen(Color.Red, 1);
                cityPen.Color    = (city_to_process == 2) ? Color.Yellow : Color.Red;
                cityPen.LineJoin = LineJoin.Round;
                pointarray       = new Point[points.Count];
                for (int x = 0; x < points.Count; x++)
                {
                    pointarray[x]   = (Point)points[x];
                    pointarray[x].X = pointarray[x].X * 20 + 10;
                    pointarray[x].Y = pointarray[x].Y * 20 + 10;
                }
                g.DrawCurve(cityPen, pointarray, 0.9f);
                cityPen.Dispose();
            }
            points.Clear();
        }