示例#1
0
    private bool isValidMove(IntVector2 _testPoint, LineClass _lineIn, bool checkUsedArray)
    {
        IntVector2 testPointReverse = _lineIn.getReverse(_testPoint);

        if (isOutsideGameGrid(_testPoint))
        {
            return(false);
        }
        if (isOutsideGameGrid(testPointReverse))
        {
            return(false);
        }

        if (isSquareABlocker(_testPoint))
        {
            return(false);
        }
        if (isSquareABlocker(testPointReverse))
        {
            return(false);
        }


        if (!_lineIn.isValidMove(_testPoint))
        {
            return(false);
        }


        if (checkUsedArray)
        {
            if (usedArray [_testPoint.x, _testPoint.y])
            {
                return(false);
            }
            if (usedArray [testPointReverse.x, testPointReverse.y])
            {
                return(false);
            }
        }
        else
        {
            for (int i = 0; i < linesList.Count; ++i)
            {
                if (i != activeLine)
                {
                    if (linesList [i].hitsLine(_testPoint))
                    {
                        return(false);
                    }
                    if (linesList [i].hitsLine(testPointReverse))
                    {
                        return(false);
                    }
                }
            }
        }
        return(true);
    }
示例#2
0
    private LineClass createLine()
    {
        bool       isFreeSpace  = false;
        IntVector2 linePosition = new IntVector2(0, 0);

        do
        {
            isFreeSpace = true;

            linePosition = new IntVector2(Random.Range(0, gameArraySize.x), Random.Range(0, gameArraySize.y));

            //Debug.Log ("test line position: " + linePosition.x + ", " + linePosition.y);
            foreach (LineClass thisLine in linesList)
            {
                if (thisLine.hitsLine(linePosition))
                {
                    //Debug.Log ("Point hits another line: " + linePosition.x + ", " + linePosition.y);
                    isFreeSpace = false;
                }
            }
        } while (!isFreeSpace);

        LineClass tempLine = new LineClass(parent, linePosition, gameArraySize, texCircle, texLine,
                                           texDashed, blockPixelSize, screenSize);

        usedArray [linePosition.x, linePosition.y] = true;
        usedSpaces++;

        for (int i = 0; i < 40; ++i)
        {
            int        directionValue = Random.Range(0, 4);
            IntVector2 directionPoint = tempLine.getDirectionPoint(directionValue);
            if (this.isValidMove(directionPoint, tempLine, true))
            {
                if (tempLine.goDirection(directionValue, false))
                {
                    // fill in array of used spaces with normal and reverse
                    usedArray [directionPoint.x, directionPoint.y] = true;
                    usedSpaces++;

                    IntVector2 directionPointReverse = tempLine.getReverse(directionPoint);
                    usedArray [directionPointReverse.x, directionPointReverse.y] = true;
                    usedSpaces++;
                }
                else
                {
                    //Debug.Log ("Unable to do direction move here - " + i);
                    //i--;
                    i++;
                }
            }
            else
            {
                //Debug.Log ("Unable to move here - " + i);
                //i--;
                i++;
            }
        }

        return(tempLine);
    }