public MapSegmentPathTile FindStartTile(ICollection <MapSegmentPathTile> tiles, MapSegmentDirection direction) { foreach (var tile in tiles) { if (MapSegmentPathTile.IsFree(tile.NeighbourUp)) { return(tile); } } // In theory; this is not possible return(null); }
public MapSegmentTraverseResult GetNextNode(MapSegmentTraverseResult lastStep) { if (lastStep.Direction == MapSegmentDirection.Up) { var nextTile = lastStep.PathTile.NeighbourRight; if (MapSegmentPathTile.IsFree(nextTile)) { return(new MapSegmentTraverseResult { PathTile = lastStep.PathTile, Direction = MapSegmentDirection.Right }); } else { if (MapSegmentPathTile.IsFree(nextTile.NeighbourUp)) { return(new MapSegmentTraverseResult { PathTile = nextTile, Direction = lastStep.Direction }); } else { return(new MapSegmentTraverseResult { PathTile = nextTile.NeighbourUp, Direction = MapSegmentDirection.Left }); } } } else if (lastStep.Direction == MapSegmentDirection.Right) { var nextTile = lastStep.PathTile.NeighbourDown; if (MapSegmentPathTile.IsFree(nextTile)) { return(new MapSegmentTraverseResult { PathTile = lastStep.PathTile, Direction = MapSegmentDirection.Down }); } else { if (MapSegmentPathTile.IsFree(nextTile.NeighbourRight)) { return(new MapSegmentTraverseResult { PathTile = nextTile, Direction = lastStep.Direction }); } else { return(new MapSegmentTraverseResult { PathTile = nextTile.NeighbourRight, Direction = MapSegmentDirection.Up }); } } } else if (lastStep.Direction == MapSegmentDirection.Down) { var nextTile = lastStep.PathTile.NeighbourLeft; if (MapSegmentPathTile.IsFree(nextTile)) { return(new MapSegmentTraverseResult { PathTile = lastStep.PathTile, Direction = MapSegmentDirection.Left }); } else { if (MapSegmentPathTile.IsFree(nextTile.NeighbourDown)) { return(new MapSegmentTraverseResult { PathTile = nextTile, Direction = lastStep.Direction }); } else { return(new MapSegmentTraverseResult { PathTile = nextTile.NeighbourDown, Direction = MapSegmentDirection.Right }); } } } else if (lastStep.Direction == MapSegmentDirection.Left) { var nextTile = lastStep.PathTile.NeighbourUp; if (MapSegmentPathTile.IsFree(nextTile)) { return(new MapSegmentTraverseResult { PathTile = lastStep.PathTile, Direction = MapSegmentDirection.Up }); } else { if (MapSegmentPathTile.IsFree(nextTile.NeighbourLeft)) { return(new MapSegmentTraverseResult { PathTile = nextTile, Direction = lastStep.Direction }); } else { return(new MapSegmentTraverseResult { PathTile = nextTile.NeighbourLeft, Direction = MapSegmentDirection.Down }); } } } // Theorically impossible but catches and handles errors // TODO: Implement exceptions and exception handling for this kind of errors return(null); }