Exemple #1
0
    private static void CheckAroundGrids(FarmGrid farmGrid, List <FarmGrid.Grid> fieldGrids, int centerGridIndex, List <int> aroundGridIndexs, bool isIgnorePutedFlag)
    {
        FarmGrid.GridPosition gridPosition = farmGrid.IndexToPosition(centerGridIndex);
        int num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x, gridPosition.y - 1, isIgnorePutedFlag);

        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
        num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x, gridPosition.y + 1, isIgnorePutedFlag);
        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
        num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x - 1, gridPosition.y, isIgnorePutedFlag);
        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
        num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x + 1, gridPosition.y, isIgnorePutedFlag);
        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
    }
Exemple #2
0
    public static List <FarmDigimonUtility.PathInfo> GetPath(int startGridIndex, int endGridIndex)
    {
        FarmRoot             instance = FarmRoot.Instance;
        FarmField            field    = instance.Field;
        List <FarmGrid.Grid> grids    = instance.Field.GetField().grids;

        bool[] array = new bool[grids.Count];
        List <FarmDigimonUtility.PathInfo> list = new List <FarmDigimonUtility.PathInfo>();
        int        num   = 0;
        List <int> list2 = new List <int>();
        List <int> list3 = new List <int>();

        list2.Add(startGridIndex);
        list.Add(new FarmDigimonUtility.PathInfo
        {
            gridIndex = startGridIndex
        });
        if (startGridIndex == endGridIndex)
        {
            return(list);
        }
        bool flag = false;

        FarmGrid.GridPosition gridPosition = field.Grid.IndexToPosition(startGridIndex);
        if (FarmDigimonUtility.CheckGrid(field.Grid, grids, gridPosition.x, gridPosition.y, false) == -1)
        {
            flag = true;
        }
        while (0 < list2.Count)
        {
            num++;
            for (int i = 0; i < list2.Count; i++)
            {
                FarmDigimonUtility.CheckAroundGrids(field.Grid, grids, list2[i], list3, false);
            }
            if (flag)
            {
                if (0 >= list3.Count)
                {
                    for (int j = 0; j < list2.Count; j++)
                    {
                        FarmDigimonUtility.CheckAroundGrids(field.Grid, grids, list2[j], list3, true);
                    }
                }
                else
                {
                    flag = false;
                }
            }
            list2.Clear();
            for (int k = 0; k < list3.Count; k++)
            {
                int num2 = list3[k];
                if (!array[num2])
                {
                    array[num2] = true;
                    list2.Add(num2);
                    list.Add(new FarmDigimonUtility.PathInfo
                    {
                        gridIndex  = num2,
                        checkPoint = num
                    });
                    if (endGridIndex == num2)
                    {
                        return(list);
                    }
                }
            }
            list3.Clear();
        }
        return(null);
    }