0

My bricks don't fully print. I get:

XXXXXXXXXX     
 XXXXXXXXX     
 XXXXXXXXX         
 XXXXXXXXX     
 XXXXXXXXX          

I can't figure out why I am missing the first brick in each of rows 2-5

initBricks(window);
{
    int Bricks + COLS * ROWS;
    int count = 0;
    int x = 0;
    int y = o;
    for (int i = o; i < ROWS; i++)   // create the bricks
    {   
        for (intj = 0; j < COLS; j++)
        {     //check for obly 10 bricks per row
            if (x >= 400)
            {
                x = o;
                Y = Y + HGTBRK;      //HGTBRK == 15;   WDBRK == 40;
            }
            else
            {
                GRect bricks = newGRect(x, y, WDBRK - 5, HGTBRK - 3);
                add (window, bricks);
            }
// then I have a switch statement that chooses color randomly. That works.
            switch            
            }
            code
            }
        x = x + WDBRK;   // I am adding the new brick
        count++;
        }
        if(count >= Bricks)
            break;
    }
}         
1
  • My mistake the bricks should look like: XXXXXXXXXX in the first row, then nine bricks starting with the second column in the next four rows – Carlos Monge Jun 9 '15 at 20:14
1

The problem is with the if/else combination. When you get to the end of each row, the next brick would be at or beyond x = 400. That triggers the then clause to reposition for the first brick in the next row.

The problem is that it never prints that next brick because the if/else clause means that you either print a brick, OR you reset to the first brick in the next row. It won't do both.

The fix is easy. Just get rid of else.

If this answers your question, please accept the answer to remove the question from the unanswered question pool. Let's keep up on forum maintenance. ;-)

2
  • This may be the answer I need, but I can't tell yet. My program was compiling and giving me the bricks I mentioned. While trying to fix the code I made matters much worse and can't compile now. I am trying to find the original download to bounce so I can see what I've done wrong. I don't know how to find that. I have messed up all my inits() and can't get anything to work. – Carlos Monge Jun 10 '15 at 0:35
  • Whenever you're working on a large or complex program, I recommend keeping it in a version control repository using a tool such as git. For example, in your ~/workspace/hacker3/breakout directory, type git init to start a new repo, then git add . to add all the files, then git commit -m "Initial commit message." to commit changes. Then you'll always be able to roll back your changes if things break. (You'll need to set up your name and email address using git config first, but Google will help.) Unfortunately, it's too late to help this time, but it's a good habit to learn! – hotwebmatter Aug 10 '16 at 0:40
0

At a glance, it seems that you are also initializing some integer variables to o (lowercase letter "O") instead of 0. That could cause you some problems, too!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .