Hi guys,
I have been trying to recreate a old game called Sokoban, we have to push boxes around a maze and place them in a defined place to win the level. I was able to get a fragment of the code from other IDE methoddology and recreate the level1 maze. See below the code I used.
It works well while in the Board, however when I transfer the code to a Class under Actor and try to use it, it crashes.
Matter of fact Greenfoot application freezes.
The Class ScenarioLoader:
Should I make the ScenarioLoader under a subClass of the Board ?
By the way this is the screenshot:

import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Board extends World {
private final int OFFSET = 30;
private final int SPACE = 20;
private Player player;
private Area area;
private Wall wall;
private Block block;
private String level1 =
" ######\n"
+ " ## #\n"
+ " ##$ #\n"
+ " #### $##\n"
+ " ## $ $ #\n"
+ "#### # ## # ######\n"
+ "## # ## ##### ..#\n"
+ "## $ $ ..#\n"
+ "###### ### #@## ..#\n"
+ " ## #########\n"
+ " ########\n";
public Board() {
super(500,300, 1);
loadLevel1();
}
public void loadLevel1() {
int x = OFFSET;
int y = OFFSET;
for (int i = 0; i < level1.length(); i++) {
char item = level1.charAt(i);
if (item == '\n') {
y += SPACE;
//if (this.w < x) {this.w = x;}
x = OFFSET;
} else if (item == '#') {
addObject(new Wall(),x,y);
x += SPACE;
} else if (item == '$') {
addObject(new Block(),x,y);
x += SPACE;
} else if (item == '.') {
addObject(new Area(),x,y);
x += SPACE;
} else if (item == '@') {
addObject(new Player(),x,y);
x += SPACE;
} else if (item == ' ') {
x += SPACE;
}
}
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Board extends World {
private ScenarioLoader sl;
public Board() {
super(500,300, 1);
ScenarioLoader sl= new ScenarioLoader();
sl.loadLevel();
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class ScenarioLoader extends Actor
{
private final int OFFSET = 30;
private final int SPACE = 20;
private Player player;
private Area area;
private Wall wall;
private Block block;
private String level1 =
" ######\n"
+ " ## #\n"
+ " ##$ #\n"
+ " #### $##\n"
+ " ## $ $ #\n"
+ "#### # ## # ######\n"
+ "## # ## ##### ..#\n"
+ "## $ $ ..#\n"
+ "###### ### #@## ..#\n"
+ " ## #########\n"
+ " ########\n";
public void act()
{
// Add your action code here.
}
public void loadLevel(){
int x = OFFSET;
int y = OFFSET;
for (int i = 0; i < level1.length(); i++) {
char item = level1.charAt(i);
if (item == '\n') {
y += SPACE;
//if (this.w < x) {this.w = x;}
x = OFFSET;
} else if (item == '#') {
getWorld().addObject(new Wall(),x,y);
x += SPACE;
} else if (item == '$') {
getWorld().addObject(new Block(),x,y);
x += SPACE;
} else if (item == '.') {
getWorld().addObject(new Area(),x,y);
x += SPACE;
} else if (item == '@') {
getWorld().addObject(new Player(),x,y);
x += SPACE;
} else if (item == ' ') {
x += SPACE;
}
}
}
}


