You are not logged in.

#1 2008-06-06 00:04:32

Yes
Member
Registered: 2008-03-29
Posts: 163

Can I get some help with a recursive function in Java?

I'm trying to make a FrozenBubble clone in Java.  I'm having trouble with the method that checks for rows with the same color.  Here's what I have now:

public int checkColors (BubbleNode node, BubbleNode prevNode, int counter) {

        counter--;
        if (node != null && prevNode != null && node.imageX != prevNode.imageX)
            return 0;            

        if (counter == 0) {
            fallingList.add (node);
            return 1;
        }
        if (node.left != null && node.left != prevNode) {
            if (checkColors (node.left, node, counter) == 1) {
                fallingList.add (node);
                return 1;
            }
            else 
                return 0;
        }
        if (node.right != null && node.right != prevNode) {
            if (checkColors (node.right, node, counter) == 1) {
                fallingList.add (node);
                return 1;
            }
            else 
                return 0;
        }
        if (node.topLeft != null && node.topLeft != prevNode) {
            if (checkColors (node.topLeft, node, counter) == 1) {
                fallingList.add (node);
                return 1;
            }
            else 
                return 0;
        }
        if (node.topRight != null && node.topRight != prevNode) {
            if (checkColors (node.topRight, node, counter) == 1)  {
                fallingList.add (node);
                return 1;
            }
            else 
                return 0;
        }
        if (node.bottomLeft != null && node.bottomLeft != prevNode) {
            if (checkColors (node.bottomLeft, node, counter) == 1) {
                fallingList.add (node);
                return 1;
            }
            else 
                return 0;
        }
        if (node.bottomRight != null && node.bottomRight != prevNode) {
            if (checkColors (node.bottomRight, node, counter) == 1) {
                fallingList.add (node);
                return 1;
            }
            else 
                return 0;
        }
   
        if (fallingList.size () > 2) {
            deleteNodes ();
        }
        return 0;
    }

The bubbles are six sided nodes, and imageX is the x coordinate for the start of the bubble in the bubble image, you can think of it as the color of the bubble.  I also posted this on the UbuntuForums here, but since it seems like the only person willing to help me has gone to bed and the program is already late, I'm thought I would also post it here.

Thanks!

Offline

Board footer

Powered by FluxBB