コード例 #1
0
        /// <summary>
        /// Start the map by adding the first cell that correspond to the starting node of the mission graph
        /// </summary>
        /// <param name="node">the starting cell that has only to be connected randomly from one direction</param>
        public void InitializeCell(Node node)
        {
            var start = new Cell(0, 0, CellType.Normal, node);

            usedSpaces.Add(start.GetLocationString(), start);
            openLocations.Add("0,0", new List <OpenNode>());
            var randDir = directions[random.Next(directions.Count)];

            openLocations["0,0"].Add(new OpenNode(randDir[0], randDir[1], start));
        }
コード例 #2
0
        /// <summary>
        /// Adding a new cell in the map and modifying the used spaces and open spaces
        /// </summary>
        /// <param name="c">the new cell that is being added</param>
        /// <param name="nextAccess">the new access level based on that cell</param>
        /// <param name="parentID">the parent id that new cell</param>
        private void AddNewNode(Cell c, int nextAccess, int parentID)
        {
            usedSpaces.Add(c.GetLocationString(), c);
            if (!openLocations.ContainsKey(parentID + "," + nextAccess))
            {
                openLocations.Add(parentID + "," + nextAccess, new List <OpenNode>());
            }

            foreach (var dir in directions)
            {
                var newX = c.x + dir[0];
                var newY = c.y + dir[1];
                if (!usedSpaces.ContainsKey(newX + "," + newY))
                {
                    openLocations[parentID + "," + nextAccess].Add(new OpenNode(newX, newY, c));
                }
            }
        }
コード例 #3
0
        /// <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)
        {
            var points = GetConnectionPoints(from, to, maxIterations);

            if (points.Count == 0)
            {
                return(false);
            }

            foreach (var p in points)
            {
                if (!usedSpaces.ContainsKey(p[0] + "," + p[1]))
                {
                    var currentCell = new Cell(p[0], p[1], CellType.Connection, null);
                    usedSpaces.Add(currentCell.GetLocationString(), currentCell);
                }
            }

            for (var i = 1; i < points.Count; i++)
            {
                var p            = points[i];
                var previousCell = usedSpaces[points[i - 1][0] + "," + points[i - 1][1]];
                var currentCell  = usedSpaces[p[0] + "," + p[1]];
                var door         = DoorType.OneWay;
                if (previousCell.node != null)
                {
                    if (previousCell.node.type == NodeType.Lever)
                    {
                        door = DoorType.LeverLock;
                    }
                }

                if (currentCell.GetDoor(currentCell.x - previousCell.x, currentCell.y - previousCell.y) == 0)
                {
                    currentCell.ConnectCells(previousCell, door);
                }
            }

            return(true);
        }
コード例 #4
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);
        }