Results 1 to 2 of 2
  1. #1
    Sasha is offline Member
    Join Date
    Jun 2013
    Posts
    4
    Rep Power
    0

    Default 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:

    Java 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);
        }
    
    }
    Java 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?

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,701
    Rep Power
    8

    Default 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?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. a little Jframe problem (im doing something wrong).
    By MR bruto in forum New To Java
    Replies: 4
    Last Post: 05-19-2013, 11:02 PM
  2. Replies: 2
    Last Post: 01-18-2013, 02:46 AM
  3. Stanford CS106a breakout assignment
    By Newbieprogrammer in forum New To Java
    Replies: 3
    Last Post: 08-14-2012, 10:18 AM
  4. Stanford Breakout Exercise
    By Newbieprogrammer in forum New To Java
    Replies: 0
    Last Post: 07-27-2012, 02:08 PM
  5. What am I doing wrong in this basic problem
    By Blaedel in forum New To Java
    Replies: 10
    Last Post: 10-11-2009, 07:45 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •