コード例 #1
0
    private void FindOtherHexagons(out Vector2 first, out Vector2 second)
    {
        Hexagon.NeighbourHexes neighbours = selectedHexagon.GetNeighbours();
        bool breakLoop = false;

        do
        {
            switch (selectionStatus)
            {
            case 0: first = neighbours.up; second = neighbours.upRight; break;

            case 1: first = neighbours.upRight; second = neighbours.downRight; break;

            case 2: first = neighbours.downRight; second = neighbours.down; break;

            case 3: first = neighbours.down; second = neighbours.downLeft; break;

            case 4: first = neighbours.downLeft; second = neighbours.upLeft; break;

            case 5: first = neighbours.upLeft; second = neighbours.up; break;

            default: first = Vector2.zero; second = Vector2.zero; break;
            }

            if (first.x < 0 || first.x >= gridWidth || first.y < 0 || first.y >= gridHeight || second.x < 0 || second.x >= gridWidth || second.y < 0 || second.y >= gridHeight)
            {
                selectionStatus = (++selectionStatus) % STATUS_COUNT;
            }
            else
            {
                breakLoop = true;
            }
        } while (!breakLoop);
    }
コード例 #2
0
    /* Helper function for FindHexagonGroup() to locate neighbours of selected hexagon */
    private void FindOtherHexagons(out Vector2 first, out Vector2 second)
    {
        Hexagon.NeighbourHexes neighbours = selectedHexagon.GetNeighbours();
        bool breakLoop = false;


        /* Picking correct neighbour according to selection position */
        do
        {
            switch (selectionStatus)
            {
            case 0: first = neighbours.up; second = neighbours.upRight; break;

            case 1: first = neighbours.upRight; second = neighbours.downRight; break;

            case 2: first = neighbours.downRight; second = neighbours.down; break;

            case 3: first = neighbours.down; second = neighbours.downLeft; break;

            case 4: first = neighbours.downLeft; second = neighbours.upLeft; break;

            case 5: first = neighbours.upLeft; second = neighbours.up; break;

            default: first = Vector2.zero; second = Vector2.zero; break;
            }

            /* Loop until two neighbours with valid positions are found */
            if (first.x < ZERO || first.x >= gridWidth || first.y < ZERO || first.y >= gridHeight || second.x < ZERO || second.x >= gridWidth || second.y < ZERO || second.y >= gridHeight)
            {
                selectionStatus = (++selectionStatus) % SELECTION_STATUS_COUNT;
            }
            else
            {
                breakLoop = true;
            }
        } while (!breakLoop);
    }
コード例 #3
0
    //This function is to find valid side hexagons
    private void findAroundHexagons(out Vector2 first, out Vector2 second, Hexagon selectedHexagon, int selectionStatus)
    {
        Hexagon.NeighbourHexes neighbours = selectedHexagon.getSidehexes();
        bool breakLoop = false;


        //Detect valid side hexagons
        do
        {
            switch (selectionStatus)
            {
            case 0: first = neighbours.up; second = neighbours.upRight; break;

            case 1: first = neighbours.upRight; second = neighbours.downRight; break;

            case 2: first = neighbours.downRight; second = neighbours.down; break;

            case 3: first = neighbours.down; second = neighbours.downLeft; break;

            case 4: first = neighbours.downLeft; second = neighbours.upLeft; break;

            case 5: first = neighbours.upLeft; second = neighbours.up; break;

            default: first = Vector2.one; second = Vector2.one; break;
            }

            //Loop until appropriate condition occures
            if (first.x < zero || first.x >= gridHeight || first.y < zero || first.y >= gridWidth || second.x < zero || second.x >= gridHeight || second.y < zero || second.y >= gridWidth)
            {
                selectionStatus = (++selectionStatus) % selectionCounter;
            }
            else
            {
                breakLoop = true;
            }
        } while (!breakLoop);
    }