Пример #1
0
    public override Vector2Int GetDoor()
    {
        int        random = Random.Range(0, WallList.Count);
        Vector2Int wall   = WallList[random];

        TreasureDic.Remove(wall);

        if (wall.x == Position.x) //left
        {
            wall += Vector2Int.left;
        }
        else if (wall.x == Position.x + Width - 1) //right
        {
            wall += Vector2Int.right;
        }
        else if (wall.y == Position.y) //down
        {
            wall += Vector2Int.down;
        }
        else if (wall.y == Position.y + Height - 1) //up
        {
            wall += Vector2Int.up;
        }

        return(wall);
    }
Пример #2
0
    protected override void SetSpace()
    {
        for (int i = Position.x; i < Position.x + Width; i++)
        {
            for (int j = Position.y; j < Position.y + Height; j++)
            {
                PositionList.Add(new Vector2Int(i, j));

                if (i == Position.x || i == Position.x + Width - 1 || j == Position.y || j == Position.y + Height - 1)
                {
                    WallList.Add(new Vector2Int(i, j));
                }
            }
        }

        Vector2Int        treasurePosition = new Vector2Int();
        List <Vector2Int> tempList         = new List <Vector2Int>(PositionList);

        for (int i = 0; i < _treasureAmount; i++)
        {
            treasurePosition = tempList[Random.Range(0, tempList.Count)];
            tempList.Remove(treasurePosition);
            if (!WallList.Contains(treasurePosition))
            {
                TreasureDic.Add(treasurePosition, new Treasure(RoomData.GetRandomTreasureID()));
            }
            else
            {
                i--;
            }
        }

        Vector2Int moneyPosition = new Vector2Int();

        for (int i = 0; i < _moneyAmount; i++)
        {
            moneyPosition = tempList[Random.Range(0, tempList.Count)];
            tempList.Remove(moneyPosition);
            if (!WallList.Contains(moneyPosition))
            {
                MoneyDic.Add(moneyPosition, Random.Range(DungeonData.MinMoney, DungeonData.MaxMoney + 1));
            }
            else
            {
                i--;
            }
        }
    }
Пример #3
0
    private void DFS(Vector2Int walker)
    {
        Vector2Int        direction = new Vector2Int();
        Vector2Int        newWalker = new Vector2Int();
        List <Vector2Int> tempList  = new List <Vector2Int>();

        while (_spaceQueue.Count > 0)
        {
            tempList = new List <Vector2Int>(_directions);
            while (tempList.Count > 0)
            {
                direction = tempList[Random.Range(0, tempList.Count)];
                newWalker = walker + direction * 2;
                if (newWalker.x >= Position.x && newWalker.x < Position.x + Width && newWalker.y >= Position.y && newWalker.y < Position.y + Height &&
                    !PositionList.Contains(newWalker))
                {
                    PositionList.Add(walker + direction);
                    PositionList.Add(walker + direction * 2);
                    _spaceQueue.Enqueue(walker + direction * 2);

                    if (walker.x == Position.x || walker.x == Position.x + Width - 1 || walker.y == Position.y || walker.y == Position.y + Height - 1)
                    {
                        WallList.Add(walker);
                    }

                    break;
                }
                else
                {
                    tempList.Remove(direction);
                }
            }

            if (tempList.Count > 0)
            {
                DFS(newWalker);
            }
            else //如果所有的方向都沒有路
            {
                if (TreasureDic.Count < _treasureAmount)
                {
                    TreasureDic.Add(walker, new Treasure(RoomData.GetRandomTreasureID()));
                }

                DFS(_spaceQueue.Dequeue());
            }
        }
    }
Пример #4
0
    protected override void SetSpace()
    {
        for (int i = Position.x; i < Position.x + Width; i++)
        {
            for (int j = Position.y; j < Position.y + Height; j++)
            {
                PositionList.Add(new Vector2Int(i, j));

                if (i == Position.x || i == Position.x + Width - 1 || j == Position.y || j == Position.y + Height - 1)
                {
                    WallList.Add(new Vector2Int(i, j));
                }
            }
        }
        TreasureDic.Add(new Vector2Int(Position.x + Width / 2, Position.y + Height / 2), new Treasure(RoomData.GetRandomTreasureID()));
    }