문제

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