Пример #1
0
        public void Highlight(PathfindingTile p, string color)
        {
            Image bit = Image.FromFile(System.IO.Directory.GetCurrentDirectory() + "/ArtAssets/Highlight" + color + ".png");

            gra.DrawImage(bit,
                          new Rectangle(
                              new Point(p.coord.graphicsX, p.coord.graphicsY),
                              new Size(GlobalClass1.graphicTileSize, GlobalClass1.graphicTileSize)));
        }
Пример #2
0
        public void PathFind(List <Tile> destList, Map map, Coordinates startPt)
        {
            //List<List<PathfindingTile>> activeList = new List<List<PathfindingTile>>();
            PathfindingTile                startTile  = new PathfindingTile(map.tileSet[startPt.x][startPt.y]);
            List <PathfindingTile>         activeList = new List <PathfindingTile>();
            List <List <PathfindingTile> > fullList   = new List <List <PathfindingTile> >();
            //List<Tile> destinations = destList;

            List <Coordinates> destCoords = new List <Coordinates>();

            foreach (Tile d in destList)
            {
                destCoords.Add(d.coord);
            }

            //Build list<list<PathfindingTile>> of entire map
            for (int i = 0; i < map.tileSet.Count(); i++)
            {
                fullList.Add(new List <PathfindingTile>());
                for (int j = 0; j < map.tileSet[0].Count(); j++)
                {
                    fullList[i].Add(new PathfindingTile(map.tileSet[i][j], -1));
                }
            }

            //Add starting position to active list
            activeList.Add(fullList[coord.x][coord.y]);


            int counter = 0;

            while (destCoords.Count() > 0)
            {
                for (int activeIndex = 0; activeIndex < activeList.Count(); activeIndex++)
                {
                    if (activeList[activeIndex].counter == 0)
                    {
                        //check if neighbor is in activelist.
                        //If not, add to activelist and assign vector.
                        //check if neighbor is a destination.  If so, remove from destination list


                        //Check if neighbor is in activelist
                        for (int i = 0; i < 4; i++)
                        {
                            int xP = activeList[activeIndex].coord.iterVect(i).x;
                            int yP = activeList[activeIndex].coord.iterVect(i).y;

                            bool inListAlready = false;

                            for (int checkIndex = 0; checkIndex < activeList.Count(); checkIndex++)
                            {
                                if (activeList[checkIndex].coord.BoolEqualCheck(activeList[activeIndex].coord.iterVect(i)))
                                {
                                    inListAlready = true;
                                }
                            }

                            if (!inListAlready)
                            {
                                //add to active list
                                activeList.Add(fullList[xP][yP]);
                                //assign direction from which it was accessed
                                activeList.Last().dir        = i;
                                activeList.Last().finalCount = counter;

                                //Check if it's a destination
                                for (int destInd = 0; destInd < destCoords.Count(); destInd++)
                                {
                                    if (destCoords[destInd].BoolEqualCheck(activeList.Last().coord))
                                    {
                                        ports.Add(activeList.Last(), activeList.Last().finalCount);
                                        courses.Add(new List <PathfindingTile>());
                                        courses.Last().Add(activeList.Last());
                                        destCoords.RemoveAt(destInd);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    activeList[activeIndex].counter--;
                }
                counter++;
            }

            //Add paths to courses

            //foreach (Tile t in destList)
            for (int destInd = 0; destInd < courses.Count(); destInd++)
            {
                //courses.Add(new List<PathfindingTile>());
                //courses.Last().Add();
                Coordinates current = courses[destInd][0].coord;
                while (!current.BoolEqualCheck(coord))
                {
                    courses[destInd].Add(
                        ActiveSearch(
                            activeList,
                            courses[destInd].Last().coord.InverseIterVect(courses[destInd].Last().dir)
                            )
                        );
                    current = courses[destInd].Last().coord;
                }
                courses[destInd].Reverse();
            }
        }