Esempio n. 1
0
    public static bool blockTypeNearby(Block block)
    {
        bool ret = false;

        //Checks 4 surrounding horizontal and vertical blocks for same colour types
        if (Blick.isInBlickArray(new Vector2((block.blickPos.x - 1), block.blickPos.y)))
        {
            if (!block.checkLeft())
            {
                Block other = GameController.accessGameController().blickGrid [(int)(block.blickPos.x - 1), (int)block.blickPos.y].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        if (Blick.isInBlickArray(new Vector2((block.blickPos.x + 1), block.blickPos.y)))
        {
            if (!block.checkRight())
            {
                Block other = GameController.accessGameController().blickGrid [(int)(block.blickPos.x + 1), (int)block.blickPos.y].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        if (Blick.isInBlickArray(new Vector2(block.blickPos.x, (block.blickPos.y + 1))))
        {
            if (!block.checkUp())
            {
                Block other = GameController.accessGameController().blickGrid [(int)block.blickPos.x, (int)(block.blickPos.y + 1)].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        if (Blick.isInBlickArray(new Vector2(block.blickPos.x, (block.blickPos.y - 1))))
        {
            if (!block.checkDown())
            {
                Block other = GameController.accessGameController().blickGrid [(int)block.blickPos.x, (int)(block.blickPos.y - 1)].getBlock();
                if (other.getType() == block.getType())
                {
                    return(true);
                }
            }
        }
        return(ret);
    }
    //CHECK NEARBY BLICK METHODS
    //ALL METHODS RETURN TRUE IF BLICK IS EMPTY, FALSE IF NOT
    public static bool checkCustom(Vector2 dest)
    {
        bool ret = false;

        if (Blick.isInBlickArray(dest))
        {
            Blick other = GameController.accessGameController().blickGrid [(int)dest.x, (int)dest.y];
            if (!other.isOccupied())
            {
                ret = true;
            }
        }
        return(ret);
    }
Esempio n. 3
0
    public int findShape(Block block, Vector2[,] map)
    {
        //Returns -1 if block was not found

        //Else returns int signifying in what orientation the shape was found
        //0 = UP
        //1 = RIGHT
        //2 = DOWN
        //3 = LEFT

        int searchResult = -1;

        if (FinishedShapeDetector.blockTypeNearby(block))
        {
            int   connections = 0;
            Block current = new Block(true), next = new Block(true);
            for (int i = 0; i < map.GetLength(0); i++)
            {
                current     = block;
                connections = 0;
                for (int j = 0; j < map.GetLength(1); j++)
                {
                    //IM NOT SURE HOW ASSIGNING WORKS IN C# IT MIGHT F**K UP SO IF SHIT GOES CRAZY LOOK AT WHAT NEXT IS CHANGING
                    Vector2 nextVector = map[i, j];
                    nextVector += current.blickPos;
                    if (Blick.isInBlickArray(nextVector))
                    {
                        if (!Block.checkCustom(nextVector))
                        {
                            next = GameController.accessGameController().blickGrid[(int)nextVector.x, (int)nextVector.y].getBlock();
                            if (Block.CompareTypes(current, next))
                            {
                                connections++;
                                current = next;
                                if (connections == 3)
                                {
                                    searchResult = i;
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (connections == 3)
                {
                    break;
                }
            }

            if (searchResult != -1)
            {
                //Remove blocks if shape was found
                current = block;
                for (int i = 0; i < 4; i++)
                {
                    if (i < 3)
                    {
                        Vector2 nextVector = map[searchResult, i] + current.blickPos;
                        next = GameController.accessGameController().blickGrid[(int)nextVector.x, (int)nextVector.y].getBlock();
                    }
                    current.removeBlock();
                    current = null;
                    current = next;
                }
            }
        }
        return(searchResult);
    }