Esempio n. 1
0
        /// <summary>
        /// connect two cells together with a certain door type
        /// </summary>
        /// <param name="other">the other cell to be connect with</param>
        /// <param name="type">the type of door connection</param>
        /// <param name="bothWays">connect both cells</param>
        public void ConnectCells(Cell other, DoorType doorType, bool bothWays = true)
        {
            var      dirX      = x - other.x;
            var      dirY      = y - other.y;
            DoorType applyType = doorType;

            if (bothWays)
            {
                applyType = DoorType.Open;
            }

            doorTypes[getDoorIndex(dirX, dirY)] = applyType;
            if (bothWays)
            {
                other.ConnectCells(this, doorType, false);
            }
        }
Esempio n. 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(Node node, int parentID)
        {
            if (node.type == NodeType.Lock)
            {
                var selected = GetWorkingLocation(parentID, node.accessLevel - 1);
                if (selected == null)
                {
                    return(false);
                }

                var newCell = new Cell(selected.x, selected.y, CellType.Normal, node);
                newCell.ConnectCells(selected.parent, DoorType.KeyLock);
                newCell.parent = selected.parent;
                AddNewNode(newCell, node.accessLevel, node.id);
            }
            else if (node.type == NodeType.Puzzle)
            {
                var selected = GetWorkingLocation(parentID, node.accessLevel);
                if (selected == null)
                {
                    return(false);
                }

                var newCell = new Cell(selected.x, selected.y, CellType.Normal, node);
                newCell.ConnectCells(selected.parent, DoorType.Open);
                newCell.parent = selected.parent;
                AddNewNode(newCell, node.accessLevel + 1, node.id);
            }
            else if (node.type == NodeType.Lever)
            {
                var selected = GetWorkingLocation(parentID, node.accessLevel);
                if (selected == null)
                {
                    return(false);
                }

                var newCell = new Cell(selected.x, selected.y, CellType.Normal, node);
                newCell.ConnectCells(selected.parent, DoorType.Open);
                newCell.parent = selected.parent;
                usedSpaces.Add(newCell.GetLocationString(), newCell);
            }
            else
            {
                var selected = GetWorkingLocation(parentID, node.accessLevel);
                if (selected == null)
                {
                    return(false);
                }

                var newCell = new Cell(selected.x, selected.y, CellType.Normal, node);
                if (selected.parent.node.type == NodeType.Puzzle)
                {
                    newCell.ConnectCells(selected.parent, DoorType.PuzzleLock);
                }
                else if (selected.parent.node.type == NodeType.Lever)
                {
                    newCell.ConnectCells(selected.parent, DoorType.LeverLock);
                }
                else
                {
                    newCell.ConnectCells(selected.parent, DoorType.Open);
                }

                if (node.GetChildren().Count == 0)
                {
                    usedSpaces.Add(newCell.GetLocationString(), newCell);
                }
                else
                {
                    AddNewNode(newCell, node.accessLevel, parentID);
                }

                newCell.parent = selected.parent;
            }

            return(true);
        }