Hi guys!
We're currently trying to create the old school Boulder Dash game in Greenfoot for our final exams.
We've just run into a weird problem..
We're trying to create a world using x's and 0's in a grid, like a lot of other people in here have.
It has always worked in other games, but not in this one.
Here's the code:
and here's the result:
Can anybody tell us what's wrong?
public BoulderWorld() { // Create a new world with 20x20 cells with a cell size of 30x30 pixels. super(20, 20, 30); populate(); } public void populate() { String worldRow; String[] world={ "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxx" }; for (int y = 0; y < 20; y++) { worldRow = world[y]; // Rækken som der indsættes i for (int x = 0; x < 20; x++) { if(worldRow.charAt(x) == 'x') // x = indsætter sten { Sand s = new Sand(); addObject(s, x*20, y*20); } if(worldRow.charAt(x) == '0') // x = indsætter sten { Dude d = new Dude(); addObject(d, x*20, y*20); } } } }
