/// <summary> /// Create the "connect" cells to connect "from" cell to "to" cell /// </summary> /// <param name="from">the starting cell</param> /// <param name="to">the end cell</param> /// <param name="maxIterations">the maximum number of trials before failing</param> /// <returns>True if the connection succeeded and False otherwise</returns> public bool makeConnection(Cell from, Cell to, int maxIterations) { List <int[]> points = this.getConnectionPoints(from, to, maxIterations); if (points.Count == 0) { return(false); } foreach (int[] p in points) { if (!this.usedSpaces.ContainsKey(p[0] + "," + p[1])) { Cell currentCell = new Cell(p[0], p[1], CellType.Connection, null); this.usedSpaces.Add(currentCell.getLocationString(), currentCell); } } for (int i = 1; i < points.Count; i++) { int[] p = points[i]; Cell previousCell = this.usedSpaces[points[i - 1][0] + "," + points[i - 1][1]]; Cell currentCell = this.usedSpaces[p[0] + "," + p[1]]; DoorType door = DoorType.Open; if (previousCell.node != null) { if (previousCell.node.type == MissionGraph.NodeType.Lever) { door = DoorType.LeverLock; } } if (currentCell.getDoor(currentCell.x - previousCell.x, currentCell.y - previousCell.y) == 0) { currentCell.connectCells(previousCell, door); } } return(true); }
/// <summary> /// Add a new cell to the layout that correspond to a certain node in the mission graph /// </summary> /// <param name="node">corresponding node in the mission graph</param> /// <param name="parentID">the id of the parent that the new cell should be connected to</param> /// <returns>True if it succeed and False otherwise</returns> public bool addCell(MissionGraph.Node node, int parentID) { if (node.type == MissionGraph.NodeType.Lock) { OpenNode selected = this.getWorkingLocation(parentID, node.accessLevel - 1); if (selected == null) { return(false); } Cell newCell = new Cell(selected.x, selected.y, CellType.Normal, node); newCell.connectCells(selected.parent, DoorType.KeyLock); newCell.parent = selected.parent; this.addNewNode(newCell, node.accessLevel, node.id); } else if (node.type == MissionGraph.NodeType.Puzzle) { OpenNode selected = this.getWorkingLocation(parentID, node.accessLevel); if (selected == null) { return(false); } Cell newCell = new Cell(selected.x, selected.y, CellType.Normal, node); newCell.connectCells(selected.parent, DoorType.Open); newCell.parent = selected.parent; this.addNewNode(newCell, node.accessLevel + 1, node.id); } else if (node.type == MissionGraph.NodeType.Lever) { OpenNode selected = this.getWorkingLocation(parentID, node.accessLevel); if (selected == null) { return(false); } Cell newCell = new Cell(selected.x, selected.y, CellType.Normal, node); newCell.connectCells(selected.parent, DoorType.Open); newCell.parent = selected.parent; this.usedSpaces.Add(newCell.getLocationString(), newCell); } else { OpenNode selected = this.getWorkingLocation(parentID, node.accessLevel); if (selected == null) { return(false); } Cell newCell = new Cell(selected.x, selected.y, CellType.Normal, node); if (selected.parent.node.type == MissionGraph.NodeType.Puzzle) { newCell.connectCells(selected.parent, DoorType.PuzzleLock); } else if (selected.parent.node.type == MissionGraph.NodeType.Lever) { newCell.connectCells(selected.parent, DoorType.LeverLock); } else { newCell.connectCells(selected.parent, DoorType.Open); } if (node.getChildren().Count == 0) { this.usedSpaces.Add(newCell.getLocationString(), newCell); } else { this.addNewNode(newCell, node.accessLevel, parentID); } newCell.parent = selected.parent; } return(true); }