質問

I'm working on a game that makes a 3x3 grid and according to the click of the user it turns it black. There are lots of help on how to draw a rectangle and fill it, but not on how to check and see if the individual rectangles are filled.

I am trying to check if each of the rectangles on the grid that the user sees on screen are filled. I have seen C# like twice in my life, so I would appreciate if someone would point me in the right direction please.

This is what I get so far:

        for (int r = 0; r < NUM_CELLS; r++)
            for (int c = 0; c < NUM_CELLS; c++)
                if(grid[r, c])
                    return true;
                else
                    return false;
役に立ちましたか?

解決

You can't return true, or you'll return true if the first element is true.

Try this:

for (int r = 0; r < NUM_CELLS; r++)
{
     for (int c = 0; c < NUM_CELLS; c++)
     {
         if(!grid[r, c])
         {
             return false;
         }
     }
}
return true;

他のヒント

    for (int r = 0; r < NUM_CELLS; r++)
        for (int c = 0; c < NUM_CELLS; c++)
            if(!grid[r, c]) 
                return false;

    return true;

What's happening here is that it is checking for complete fullness, so if anything is empty it returns false, if nothing is empty it exits out of the two loops and just returns true

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top