コード例 #1
0
 public void RemoveCurrentPosition()
 {
     if (CurrentPosition == null)
     {
         return;
     }
     if (PositionList.Contains(CurrentPosition))
     {
         PositionList.Remove(CurrentPosition);
     }
     CurrentPosition = null;
 }
コード例 #2
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());
            }
        }
    }
コード例 #3
0
 public bool ContainsPane(Pane pane)
 {
     return(PositionList.Contains(pane));
 }