# Issues with Populating an Arraylist within a blockbreaker game

• 06-02-2011, 06:09 PM
pumpbreaks
Issues with Populating an Arraylist within a blockbreaker game
hello everyone!

I am studying computer science in uni and i have been given a block breaking game assignment, i have got the ball to move and bounce off each wall, bounce off the paddle, move the paddle, lose a life and game over. This was with lots of help from my tutor.

I need to write a nested for loop to populate an array list with bricks and I've been looking everywhere how to do this. I just can't get my head around this problem and i feel like I've exhausted every option. I'm hoping you guys can help me progress and work out how to get this done as I'm panicking a little bit as it's due in on Wednesday and my head feels totally blagged.

i have a class called ArrayBrick:
Code:

```package blockbreakerextreme; import java.util.ArrayList; /**  *  * @author 1097  */ public class ArrayBrick {     int index = 0;     Brick brick; ArrayList<Brick> allBrick = new ArrayList<Brick>(); public int getIndex(){ return index;     } public void add(Brick brick) {         allBrick.add(brick);     }     public Brick getBrick(int index) {         brick = allBrick.get(index);         return brick;     }       public int getAllBricks() {         return allBrick.size();     }       public void remove(int index) {         allBrick.remove(index);       } }```
in my game panel i have created a new instance of ArrayBrick and brick and the arraylist, (i have one brick just drawn to prove the brick would show)

i need to write a method to populate the array list with bricks this is what i have in PanelGame

the bricks need to be spaced 10 by 3

Code:

```            static Brick brick;     static ArrayBrick array;     ArrayList<Brick> allBrick = new ArrayList<Brick>();  public void loadBricks() {         //this is where i am stuck     }```
i hope you guys can help me out,

pumpbreaks
• 06-02-2011, 06:36 PM
Tolls
Code:

```    static ArrayBrick array;     ArrayList<Brick> allBrick = new ArrayList<Brick>();```
Your ArrayBrick already has an ArrayList<Brick> in it, so what is this other one for?
• 06-02-2011, 06:39 PM
pumpbreaks
I have gotten confused, i dont need that in there. as i said i am not very good.

• 06-02-2011, 10:06 PM
pumpbreaks
this is what i have so far

public void loadBricks() {
for (int i = 0; i < 30;i++){