Esempio n. 1
0
    List <List <int> > GetListFromBoolean2D(Boolean2D pArray)
    {
        List <List <int> > mapList = new List <List <int> >();

        for (int i = 0; i < mapSize; i++)
        {
            for (int j = 0; j < mapSize; j++)
            {
                bool value;

                if (pArray.GetElement(i, j, out value) && !value)
                {
                    mapList.Add(null);
                    continue;
                }
                List <int> resultList = new List <int>();

                AddResult(i - 1, j, resultList, pArray, 0);
                AddResult(i, j + 1, resultList, pArray, 2);
                AddResult(i + 1, j, resultList, pArray, 4);
                AddResult(i, j - 1, resultList, pArray, 6);

                if (useObliqueLine)
                {
                    AddResult(i - 1, j + 1, resultList, pArray, 1);
                    AddResult(i + 1, j + 1, resultList, pArray, 3);
                    AddResult(i + 1, j - 1, resultList, pArray, 5);
                    AddResult(i - 1, j - 1, resultList, pArray, 7);
                }

                mapList.Add(resultList);
            }
        }
        return(mapList);
    }
Esempio n. 2
0
    void AddResult(int i, int j, List <int> list, Boolean2D pArray, int result)
    {
        bool value;

        if (pArray.GetElement(i, j, out value) && value)
        {
            list.Add(result);
        }
    }
Esempio n. 3
0
 public Boolean2D(Boolean2D copy)
 {
     array       = new bool[copy.oneSideSize * copy.oneSideSize];
     oneSideSize = copy.oneSideSize;
     for (int i = 0; i < array.Length; i++)
     {
         array[i] = copy.array[i];
     }
 }
Esempio n. 4
0
    public void ResetMap()
    {
        if (_position == Vector2.down)
        {
            _position = currentPosition;
        }
        else
        {
            currentPosition = _position;
        }

        _pointArray = new Boolean2D(pointArray);
        _mapList    = GetListFromBoolean2D(pointArray);
    }
Esempio n. 5
0
    public List <int> GetArrayFromMap()
    {
        if (_pointArray.IsEmpty())
        {
            _pointArray = new Boolean2D(pointArray);
        }

        List <List <int> > mapList = canWalkBack ? _mapList : GetListFromBoolean2D(_pointArray);

        if (!canWalkBack)
        {
            _pointArray.SetElement((int)currentPosition.x, (int)currentPosition.y, false);
        }

        int index = (int)(currentPosition.x * mapSize + currentPosition.y);

        if (mapList[index] == null)
        {
            Debug.LogError("请将PositionInMap的初始值设在路径上!");
            return(null);
        }

        return(mapList[index]);
    }