I am trying to create an abstract world in Greenfoot. I have created this code:
But whenever I compile this code I get an infinite loop. I thought this was just because it was abstract, so I made a new class:
However, I'm still getting the same problem. Does anyone know why I'm getting an infinite loop? Is there any way to not try and load in the Scene class graphically?
Thanks in advance,
RealFighter64
Edit: I forgot, I also made two classes for abstract tiling, in case it matters.:
SpecialTile:
Block
The image is a custom made one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import greenfoot.*; import java.util.*; public abstract class Scene extends World { int [][] map; ArrayList<Actor> tileset; public Scene( int width, int height) { super (width, height, 64 ); map = new int [height][width]; tileset = new ArrayList<Actor>(); this .addTiles(); this .createMap(); this .prepare(); } public void prepare() { for ( int i = 0 ; i < tileset.size(); i++) { for ( int y = 0 ; y < map.length; y++) { for ( int x = 0 ; x < map[y].length; x++) { if (map[y][x] == i) { this .addObject(tileset.get(i), x, y); } } } } } public void addTile(Actor tile) { tileset.add(tile); } public void setMapTile( int x, int y, int tile) { map[y][x] = tile; } public abstract void addTiles(); public abstract void createMap(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import greenfoot.*; /** * Write a description of class Level1 here. * * @author (your name) * @version (a version number or a date) */ public class Level1 extends Scene { public Level1() { super ( 8 , 8 ); } @Override public void addTiles() { this .addTile( new Block()); } public void createMap() { this .setMapTile( 0 , 0 , 0 ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 | import greenfoot.*; /** * Write a description of class SpecialTile here. * * @author (your name) * @version (a version number or a date) */ public abstract class SpecialTile extends Actor { public abstract void action(String action); } |
1 2 3 4 5 6 | import greenfoot.*; public class Block extends Actor { } |