Пример #1
0
    public SquareGraphElem LookAround(Square square, LookAroundFunc BreakPoint, LookAroundFuncReturn Return, bool ignorePlayers = false, bool dangerIsNotWalkable = false)
    {
        ExtraSquareInfo squareInfo = square.GetComponent <ExtraSquareInfo>();

        currentStep = new List <SquareGraphElem>();
        currentStep.Add(new SquareGraphElem(square));

        MarkDanger();

        for (int x = 0; x < 10; x++)
        {
            int loopCount = currentStep.Count;
            for (int i = loopCount - 1; i >= 0; i--)
            {
                SquareGraphElem currentSquare = currentStep[i];
                squareInfo = currentSquare.mySquare.GetComponent <ExtraSquareInfo>();
                if (squareInfo.visited)
                {
                    currentStep.RemoveAt(i);
                    continue;
                }

                squareInfo.visited = true;

                if (!BreakPoint(currentSquare))
                {
                    //print("break");
                    ClearBoard();
                    return(Return(currentSquare));
                }
            }

            loopCount = currentStep.Count;
            for (int i = 0; i < loopCount; i++)
            {
                SquareGraphElem currentSquare = currentStep[i];

                foreach (Square neighbour in currentSquare.mySquare.Neighbours)
                {
                    if (!neighbour.Walkable(ignorePlayers, !dangerIsNotWalkable) || neighbour.info.visited)
                    {
                        continue;
                    }
                    SquareGraphElem newSquareGraphElem = new SquareGraphElem(neighbour);
                    currentStep.Add(newSquareGraphElem);
                    Connect(newSquareGraphElem, currentSquare);
                }
            }
        }

        ClearBoard();

        //print("no break");
        return(new SquareGraphElem(square));
    }
Пример #2
0
    public void ClearBoard()
    {
        foreach (Transform child in Board.main.transform)
        {
            ExtraSquareInfo squareInfo = child.GetComponent <ExtraSquareInfo>();
            if (!squareInfo)
            {
                return;
            }

            squareInfo.visited = false;
            squareInfo.danger  = false;
        }
    }
Пример #3
0
    void LookAroundStep(bool ignorePlayers = false, bool ignoreDanger = true, bool ignoreDestructable = false, bool ignoreBombs = false)
    {
        int loopCount = currentStep.Count;

        for (int i = loopCount - 1; i >= 0; i--)
        {
            SquareGraphElem currentSquare = currentStep[i];
            if (currentSquare.mySquare == null)
            {
                print("no square!");
                continue;
            }

            ExtraSquareInfo squareInfo = currentSquare.mySquare.info;
            if (squareInfo.visited)
            {
                currentStep.RemoveAt(i);
                continue;
            }

            squareInfo.visited = true;
        }

        loopCount = currentStep.Count;
        for (int i = 0; i < loopCount; i++)
        {
            SquareGraphElem currentSquare = currentStep[i];

            foreach (Square neighbour in currentSquare.mySquare.Neighbours)
            {
                if (!neighbour.Walkable(ignorePlayers, ignoreDanger, ignoreDestructable, ignoreBombs) || neighbour.info.visited)
                {
                    continue;
                }
                SquareGraphElem newSquareGraphElem = new SquareGraphElem(neighbour);
                currentStep.Add(newSquareGraphElem);
                Connect(newSquareGraphElem, currentSquare);
            }
        }
    }
Пример #4
0
    public void SetUp()
    {
        Neighbours = new List <Square>();
        if (Up)
        {
            Neighbours.Add(Up);
        }
        if (Down)
        {
            Neighbours.Add(Down);
        }
        if (Right)
        {
            Neighbours.Add(Right);
        }
        if (Left)
        {
            Neighbours.Add(Left);
        }

        info = GetComponent <ExtraSquareInfo>();
    }