Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startCell"></param>
        /// <param name="endCell"></param>
        /// <param name="diagonal"></param>
        /// <param name="movementPoints"></param>
        /// <param name="obstacles"></param>
        /// <returns></returns>
        public string FindPathAsString(int startCell, int endCell, bool diagonal, int movementPoints = -1, IEnumerable <int> obstacles = null)
        {
            var movementPath = FindPath(startCell, endCell, diagonal, movementPoints, obstacles == null ? new List <int>() : obstacles);

            StringBuilder PathAsString = new StringBuilder();

            for (int i = 0; i <= movementPath.Count() - 2; i++)
            {
                PathAsString.Append(Pathfinding.GetDirectionChar((Pathfinding.GetDirection(map, movementPath.ElementAt(i), movementPath.ElementAt(i + 1)))));
                PathAsString.Append(Util.CellToChar(movementPath.ElementAt(i + 1)));
            }

            return(PathAsString.ToString());
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="map"></param>
        /// <param name="cellId"></param>
        /// <param name="currentCell"></param>
        /// <param name="range"></param>
        /// <returns></returns>
        public static IEnumerable <int> GetCells(MapInstance map, int cellId, int currentCell, string range)
        {
            switch (range[0])
            {
            case 'C':
                if (range[1] == '_')
                {
                    foreach (var cell in map.Cells)
                    {
                        yield return(cell.Id);
                    }
                    yield break;
                }
                else
                {
                    foreach (var cell in GetCircleCells(map, cellId, Util.HASH.IndexOf(range[1])))
                    {
                        yield return(cell);
                    }
                }
                break;

            case 'X':
                foreach (var cell in GetCrossCells(map, cellId, Util.HASH.IndexOf(range[1])))
                {
                    yield return(cell);
                }
                break;

            case 'T':
                foreach (var cell in GetTLineCells(map, cellId, Pathfinding.GetDirection(map, currentCell, cellId), Util.HASH.IndexOf(range[1])))
                {
                    yield return(cell);
                }
                break;

            case 'L':
                foreach (var cell in GetLineCells(map, cellId, Pathfinding.GetDirection(map, currentCell, cellId), Util.HASH.IndexOf(range[1])))
                {
                    yield return(cell);
                }
                break;

            default:
                yield return(cellId);

                break;
            }
        }