# What is wrong? Stanford SC106a Breakout Problem

• 06-19-2013, 05:17 AM
Sasha
What is wrong? Stanford SC106a Breakout Problem
Hi everybody, I hope the following makes sense, I am still learning. Thanks in advance for your help!

I am currently going through the Stanford Program Methodology class. For Assignment #3, I am writting Woz's Breakout program, basically 10 rows of multi-colored bricks, a mouse-controlled paddle and a ball that breaks the bricks on impact. I am not very experienced so I just started setting up bricks within the the run() method. It ran fine, I was able to see the rows of multi-colored bricks within the applet window. Then I decided to have separate classes for each of the bullet points below. I decomposed the program as follows:

• Write a class that holds all the constants (done)
• Set up Bricks on top of the screen
• Set up the moving Paddle
• Set up the ball
• Write a run method that calls all the above and brings it all together

I got the constants class working no problem but I am having issues with Bricks method and the run(). I think I am not calling Bricks correctly.

Here is my code for the Bricks class:

Code:

```/*  * File: Bricks.java  * -----------------  * This class sets up bricks for the Breakout game.  */ import acm.graphics.*; import acm.program.*; import java.awt.*; public class Bricks extends GraphicsProgram {       public Bricks(double x, double y) {         //double x; // = 0;         //double y; // = BC.BRICK_Y_OFFSET;               Color c = null;               for (int i = 0; i < BC.NBRICK_ROWS; i++){                       /* Changes color every 2 rows. */             if (i == 0 || i == 1) {                 c = Color.RED;                 }             if (i == 2 || i == 3) {                 c = Color.ORANGE;                 }             if (i == 4 || i == 5) {                 c = Color.YELLOW;                 }             if (i == 6 || i == 7) {                 c = Color.GREEN;                 }             if (i == 8 || i == 9) {                 c = Color.CYAN;                 }             drawRowOfBricks(x, y, BC.NBRICKS_PER_ROW, c);             y = y + BC.BRICK_HEIGHT + BC.BRICK_SEP;         }     }       /* Draws one row of bricks. */     private void drawRowOfBricks(double x, double y, int bricks, Color c) {         for (int i = 0; i < BC.NBRICKS_PER_ROW; i++) {             drawBrick((x + i * BC.BRICK_WIDTH), y, c);             x += BC.BRICK_SEP;         }     }           /* Draws one brick */     private void drawBrick(double x, double y, Color c) {         GRect brick = new GRect (x, y, BC.BRICK_WIDTH, BC.BRICK_HEIGHT);         add(brick);         brick.setFilled(true);         brick.setColor(c);     } }```
Code:

```/*  * File: Breakout.java  * -------------------  * This file will implements the game Breakout.  */ import acm.graphics.*; import acm.program.*; import acm.util.*; import java.applet.*; import java.awt.*; import java.awt.event.*; public class Breakout extends GraphicsProgram {       public void init() {         setSize(400, 600);     }       /* Method: run() */     /** Runs the Breakout program. */     public void run() {         Bricks bricks = new Bricks(BC.BRICK_WIDTH, BC.BRICK_HEIGHT);         add(bricks, 0, BC.BRICK_Y_OFFSET);          } }```
I just want to see that the program is working prior to proceeding with the other classes. What is wrong?
• 06-19-2013, 03:54 PM
KevinWorkman
Re: What is wrong? Stanford SC106a Breakout Problem
This code isn't really complete enough for us to debug. I don't recommend posting your whole program, but creating an SSCCE will go a long way towards getting help.

I'm not really sure what this program is supposed to do. You extend GraphicsProgram twice (we don't know what GraphicsProgram is), and then add one GraphicsProgram to the other, and... then what? What should happen next?