예제 #1
0
        public PathFinder()
        {
            Dictionary<int, PFCell> tempGaps = null;
            grid = new PFCell[GameMap.I.ColCount, GameMap.I.RowCount];
            var protoMX = GameMap.I.ProtoMX;
            for (int i = 0; i < grid.GetLength(0); i++)
                for (int j = 0; j < grid.GetLength(1); j++)
                {
                    var cell = new PFCell(GetPathFindActualCellType(protoMX[i, j]), i, j);

                    if (cell.Type != CellType.Wall)
                    {
                        pasibilityCells.Add(cell);
                        if (cell.Type == CellType.Gap)
                        {
                            if (tempGaps == null) tempGaps = new Dictionary<int, PFCell>();
                            tempGaps.Add(i * COL_MULTIPLY + j, cell);
                        }
                    }

                    grid[i, j] = cell;
                }

            if (tempGaps != null) ReverseGapKeys(tempGaps);
        }
예제 #2
0
        private void BuildPath(PFCell previusCell)
        {
            findingPath.Add(previusCell);
            var currCol = previusCell.Col;
            var currRow = previusCell.Row;

            for (int i = 0; i < ambit.Length - 1; i += 2)
            {
                var cellNear = GetCellNear(currCol + ambit[i], currRow + ambit[i + 1], previusCell);
                if (cellNear != null && cellNear.Mark == previusCell.Mark - 1)
                {
                    if (cellNear.Mark != BEGIN_MARK)
                        BuildPath(cellNear);
                    else
                        findingPath.Add(cellNear);
                    break;
                }
            }
        }
예제 #3
0
        private PFCell GetCellNear(int col, int row, PFCell currCell)
        {
            if (row >= grid.GetLength(1) || col >= grid.GetLength(0) || row < 0 || col < 0)
                if (currCell.Type == CellType.Gap)
                    return gaps[currCell.Col * COL_MULTIPLY + currCell.Row];
                else
                    return null;

            if (grid[col, row].Type == CellType.Wall)
                return null;
            else
                return grid[col, row];
        }