当前位置: 首页>>代码示例>>C#>>正文


C# Room.addDoor方法代码示例

本文整理汇总了C#中Room.addDoor方法的典型用法代码示例。如果您正苦于以下问题:C# Room.addDoor方法的具体用法?C# Room.addDoor怎么用?C# Room.addDoor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Room的用法示例。


在下文中一共展示了Room.addDoor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: addNode

    /// <summary>
    /// Generate the level iteratively using breadth first generate
    /// </summary>
    /// <param name="map">Map of the entire level</param>
    /// <param name="toBeGenerated">List (Queue) of rooms that are waiting to be added</param>
    /// <param name="roomCount">Current number of rooms</param>
    private int addNode(Dictionary<Vector2, Room> map, List<Room> toBeGenerated, int roomCount)
    {
        //While there are more rooms
        while (toBeGenerated.Count > 0)
        {
            //Grab to top room and remove it from toBeGenerated
            Room current = toBeGenerated[0];
            toBeGenerated.RemoveAt(0);

            //If the room is already in the map
            Room inMap;
            if (map.TryGetValue(current.position, out inMap))
            {
                //Give it any new doors
                for (int e = 0; e < current.doors.Length; ++e)
                {
                    if (current.doors[e] && !inMap.doors[e])
                    {
                        inMap.addDoor(e);
                    }
                }
            }//If the room isn't already in the map, we need to generate it
            else
            {
                //Add it to the map
                map.Add(current.position, current);

                //How many doors this room has
                int doorCount = 0;

                //Buffs the chance of getting new rooms
                float buff = 0;
                //Buff the first room to make a spiderweb instead of a pole
                if (roomCount == 1)
                {
                    buff = 3.0f;
                }
                //Go through each door for the room
                for (int e = 0; e < 4; ++e)
                {
                    //If we are at the max room count, break
                    if (roomCount == curMaxSize)
                    {
                        break;
                    }
                    //If a door here does not already exist
                    if (!current.doors[e])
                    {

                        //Check to see if this room wants another door based on an algorithm
                        if (Random.Range(Mathf.Log(DifficultyTracker.difficultyTrack.getDifficulty() * DifficultyManager.dManager.floor) + buff, 10.0f + Mathf.Log(DifficultyTracker.difficultyTrack.getDifficulty() * DifficultyManager.dManager.floor) + (0.5f * doorCount)) > 5.0f)
                        {
                            Room temp;
                            //Make it harder to punch into existing rooms
                            if (!map.TryGetValue(dirToPos(current.position, e), out temp) || Random.Range(0.0f, 10.0f) > 2.0f)
                            {
                                //If the room in the given direction does exist, connect them
                                if (temp != null)
                                {
                                    temp.addDoor(oppositeDirection(e));
                                    current.addDoor(e);
                                }//If the room in the given direction doesn't exist
                                else if (roomCount < curMaxSize)
                                {
                                    //Increment room count
                                    ++roomCount;

                                    //Create the new room and connect them
                                    Room newRoom = new Room();
                                    newRoom.position = dirToPos(current.position, e);
                                    newRoom.addDoor(oppositeDirection(e));
                                    current.addDoor(e);

                                    //Add the new room to the queue
                                    toBeGenerated.Add(newRoom);

                                    //If we are at the max room count, break
                                    if (roomCount == curMaxSize)
                                    {
                                        break;
                                    }
                                }

                            }
                        }
                    }
                }
            }
        } 
        return roomCount;
    }
开发者ID:bobjrsenior,项目名称:The_Final_Mage_2,代码行数:97,代码来源:LevelGen.cs


注:本文中的Room.addDoor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。