コード例 #1
0
            private MapSection Visit(ICell cell)
            {
                Stack <ICell> stack      = new Stack <ICell>(new List <ICell>());
                MapSection    mapSection = new MapSection();

                stack.Push(cell);
                while (stack.Count != 0)
                {
                    cell = stack.Pop();
                    if (_visited[cell.Y][cell.X] || !cell.IsWalkable)
                    {
                        continue;
                    }
                    mapSection.AddCell(cell);
                    _visited[cell.Y][cell.X] = true;
                    foreach (ICell neighbor in GetNeighbors(cell))
                    {
                        if (cell.IsWalkable == neighbor.IsWalkable && !_visited[neighbor.Y][neighbor.X])
                        {
                            stack.Push(neighbor);
                        }
                    }
                }
                return(mapSection);
            }
コード例 #2
0
            private MapSection Visit(Cell cell)
            {
                Stack <Cell> stack      = new Stack <Cell>(new List <Cell>());
                MapSection   mapsection = new MapSection();

                stack.Push(cell);
                while (stack.Count != 0)
                {
                    cell = stack.Pop();
                    if (_visited[cell.Point.Y][cell.Point.X] || !cell.IsWalkable)
                    {
                        continue;
                    }
                    mapsection.AddCell(cell);
                    _visited[cell.Point.Y][cell.Point.X] = true;
                    //foreach ( Cell neighbor in GetNeighbors(cell.Point) )
                    //{
                    //   if ( cell.IsWalkable == neighbor.IsWalkable && !_visited[neighbor.Y][neighbor.X] )
                    //   {
                    //      stack.Push( neighbor );
                    //   }
                    //}
                }
                return(mapsection);
            }
コード例 #3
0
            public List <MapSection> GetMapSections()
            {
                foreach (Cell cell in _map.GetAllCells())
                {
                    if (!cell.IsWalkable)
                    {
                        continue;
                    }
                    bool foundSection = false;
                    foreach (MapSection mapSection in _mapSections)
                    {
                        Path shortestPath = null;
                        try
                        {
                            shortestPath = _pathFinder.ShortestPath(cell, mapSection.Cells.First());
                        }
                        catch (PathNotFoundException)
                        {
                        }

                        if (shortestPath != null)
                        {
                            mapSection.AddCell(cell);
                            foundSection = true;
                            break;
                        }
                    }
                    if (!foundSection)
                    {
                        var mapSection = new MapSection();
                        mapSection.AddCell(cell);
                        _mapSections.Add(mapSection);
                    }
                }
                return(_mapSections);
            }