예제 #1
0
        /// <summary>
        /// Get an empty location that has a specific access level and connected to a certain node
        /// </summary>
        /// <param name="parentID">the node id that need to be connected to</param>
        /// <param name="accessLevel">the access level that the cell need to be at</param>
        /// <returns>the empty location that has a certain parent id and access level</returns>
        private OpenNode getWorkingLocation(int parentID, int accessLevel)
        {
            if (!this.openLocations.ContainsKey(parentID + "," + accessLevel))
            {
                return(null);
            }
            Helper.shuffleList(this.random, this.openLocations[parentID + "," + accessLevel]);
            OpenNode selected = null;

            foreach (OpenNode loc in this.openLocations[parentID + "," + accessLevel])
            {
                if (!this.usedSpaces.ContainsKey(loc.x + "," + loc.y))
                {
                    selected = loc;
                    break;
                }
            }
            return(selected);
        }
예제 #2
0
 /// <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);
 }