public void DrawLegalBlockFromCoupler(LineCoupler lc)
    {
        GameObject gridObj = null;

        int[] coord = lc.GetComponentInParent <GridBehaviour>().coordinates;
        List <List <GameObject> > grid = GameManager.Instance.grid;

        gridMan.ResetLegalBlocks();

        switch (lc.dir)
        {
        case DIRECTION.LEFT:
            gridObj = grid[coord[0] - 1][coord[1]];
            break;

        case DIRECTION.RIGHT:
            gridObj = grid[coord[0] + 1][coord[1]];
            break;

        case DIRECTION.TOP:
            gridObj = grid[coord[0]][coord[1] + 1];
            break;

        case DIRECTION.BOTTOM:
            gridObj = grid[coord[0]][coord[1] - 1];
            break;
        }

        if (CheckGridForLegalBlock(gridObj))
        {
            gridMan.legalBlockFeedback[0].transform.position = gridObj.transform.position;
        }
    }
Example #2
0
    bool CheckIfMoveIsLegal()
    {
        bool success = true;

        gridMan.ResetIllegalBlock();
        Line line = lineMan.currentLineBeingDrawn;

        // Check if the block is already occupied
        if (currentLine != null ||
            GetComponent <GridBehaviour>().currentBlockType.blockType != BLOCK.EMPTY)
        {
            success = false;
        }
        else
        {
            List <LineController> linePath = line.linePath;
            int[] thisCoord = GetComponentInParent <GridBehaviour>().coordinates;
            int[] prevCoord;
            // Legal move checking from a coupler is more specific
            LineCoupler fromCoupler = null;

            if (line.linePath.Count == 0)
            {
                fromCoupler = line.lineCouplers[0];
                prevCoord   = fromCoupler.GetComponentInParent <GridBehaviour>().coordinates;
            }
            else
            {
                prevCoord = linePath[linePath.Count - 1].GetComponentInParent <GridBehaviour>().coordinates;
            }

            int xDiff = Mathf.Abs(thisCoord[0] - prevCoord[0]);
            int yDiff = Mathf.Abs(thisCoord[1] - prevCoord[1]);

            success = CheckLegalDirection(xDiff, yDiff, fromCoupler);
        }

        return(success);
    }