public static ConcreteGraph CreateGraph(int width, int height, IPassability passability) { var graph = new ConcreteGraph(); CreateNodes(width, height, graph, passability); CreateEdges(graph, width, height, TileType.Octile); // We hardcode OCTILE for the time being return(graph); }
public ConcreteMap(TileType tileType, int width, int height, IPassability passability) { Passability = passability; TileType = tileType; MaxEdges = Helpers.GetMaxEdges(tileType); Height = height; Width = width; Graph = GraphFactory.CreateGraph(width, height, Passability); }
public static Graph<TilingNodeInfo, TilingEdgeInfo> CreateGraph(int width, int height, IPassability passability) { var graph = new Graph<TilingNodeInfo, TilingEdgeInfo>(); CreateNodes(width, height, graph, passability); CreateEdges(graph, width, height, TileType.OCTILE); // We hardcode OCTILE for the time being return graph; }
private static void CreateNodes(int width, int height, Graph<TilingNodeInfo, TilingEdgeInfo> graph, IPassability passability) { for (var top = 0; top < height; ++top) for (var left = 0; left < width; ++left) { var nodeId = GetNodeIdFromPos(left, top, width); var position = new Position(left, top); int movementCost; var isObstacle = !passability.CanEnter(position, out movementCost); var info = new TilingNodeInfo(isObstacle, movementCost, new Position(left, top)); graph.AddNode(nodeId, info); } }
private static void CreateNodes(int width, int height, ConcreteGraph graph, IPassability passability) { for (var top = 0; top < height; ++top) { for (var left = 0; left < width; ++left) { var nodeId = GetNodeIdFromPos(left, top, width); var position = new Position(left, top); int movementCost; var isObstacle = !passability.CanEnter(position, out movementCost); var info = new ConcreteNodeInfo(isObstacle, movementCost, position); graph.AddNode(nodeId, info); } } }
// Create a new concreteMap as a copy of another concreteMap (just copying obstacles) public ConcreteMap Slice(int horizOrigin, int vertOrigin, int width, int height, IPassability passability) { var slicedConcreteMap = new ConcreteMap(this.TileType, width, height, passability); // so we now put the obstacles in place for (var x = 0; x < width; x++) for (var y = 0; y < height; y++) { // get the local node var localNodeInfo = slicedConcreteMap.Graph.GetNode(slicedConcreteMap.GetNodeIdFromPos(x, y)).Info; // get the initial concreteMap node var nodeInfo = this.Graph.GetNode(this.GetNodeIdFromPos(horizOrigin + x, vertOrigin + y)).Info; // set obstacle for the local node localNodeInfo.IsObstacle = nodeInfo.IsObstacle; localNodeInfo.Cost = nodeInfo.Cost; } return slicedConcreteMap; }
public ConcreteMap(TileType tileType, int width, int height, IPassability passability) { Passability = passability; this.Init(tileType, width, height); }
// Create a new concreteMap as a copy of another concreteMap (just copying obstacles) public ConcreteMap Slice(int horizOrigin, int vertOrigin, int width, int height, IPassability passability) { var slicedConcreteMap = new ConcreteMap(this.TileType, width, height, passability); foreach (var slicedMapNode in slicedConcreteMap.Graph.Nodes) { var globalConcreteNode = Graph.GetNode(GetNodeIdFromPos(horizOrigin + slicedMapNode.Info.Position.X, vertOrigin + slicedMapNode.Info.Position.Y)); slicedMapNode.Info.IsObstacle = globalConcreteNode.Info.IsObstacle; slicedMapNode.Info.Cost = globalConcreteNode.Info.Cost; } return(slicedConcreteMap); }
public static ConcreteMap CreateTiling(int width, int height, IPassability passability, TileType tilingType = TileType.OCTILE) { var tiling = new ConcreteMap(tilingType, width, height, passability); return tiling; }
public static ConcreteMap CreateTiling(int width, int height, IPassability passability, TileType tilingType = TileType.Octile) { var tiling = new ConcreteMap(tilingType, width, height, passability); return(tiling); }