Results 1 to 5 of 5
  1. #1
    Ceasar is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default Need a loop for rows and columns

    hey guys i need help making a loop to create bricks in my breakout game.

    here is the code to make one brick:

    //creates a brick in breakoutWourld.
    brick = new Brick(1,"red");
    addToGame(brick, 20, 10);


    any ideas on how i can loop it to make 2 rows that have 11 bricks.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    Read your text book. I'm sure it covers how to do "for loops".

    If you don't have your text book handy then you can always use the Sun tutorial. You can start with Language Basics.

  3. #3
    Ceasar is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    If i used the code to make all the bricks of the game how can i change the colours between them?

    for (int i = 0; i < 8; i++)
    {
    for (int j = 0; j < 11; j++)
    {
    brick = new Brick(1,"red");
    addToGame(brick,20+j*BRICK_WIDTH,10+i*BRICK_HEIGHT );
    }
    }

    at the moment its making all the bricks red.

    i have four colors red, blue, green, yellow. and after every second row i need the color to change.
    Edit/Delete Message

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  5. #5
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    look at the Random class. You can set it up to give you a random value from 1-4 and then based on that number have a case statement that determines the color.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. Jlist Columns
    By DenRed in forum New To Java
    Replies: 2
    Last Post: 10-02-2009, 09:33 AM
  2. Counting Rows and Columns from Excel Sheet
    By Anish in forum Advanced Java
    Replies: 3
    Last Post: 12-24-2008, 06:56 AM
  3. How to get the no. of rows in a resultset
    By baskar.nitt in forum New To Java
    Replies: 5
    Last Post: 09-19-2008, 01:30 PM
  4. Two diM aRRay and add rows and columns....
    By filly444 in forum New To Java
    Replies: 2
    Last Post: 08-30-2008, 05:24 PM
  5. Fetching rows from DB
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-06-2008, 09:23 AM

Posting Permissions

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