Search code examples
c#fillrectanglesis-empty

Check if a rectangle is filled


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;

Solution

  • 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;