@thssfrnssssmnt I am trying to figure out something, I don't really have time to "set a score" on your game :)
@danpost
it is still not working, it says: cannot reference myTwoDArray before supertype constructor has been called
My mainWorldClass:
my game class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class mainWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MainWorldClass extends World/*Or whatever you want to call it*/
{
private int[][] world;
public MainWorldClass(int[][] array)
{
super(800, 400, 1);
world = array;
}
public void setItemsFromArray(int[][] world)
{
int gap = 30; // see note below
for (int i = 0; i < world.length; i++) for (int j = 0; j < world[i].length; j++)
{
Actor actor = null; // to hold any actor created
switch (world[i][j]) {
case 0: break; // no actor here
case 1: actor = new Player(); break;
case 2: actor = new Enemy(); break;
case 3: actor = new Wall(); break;
case 4: actor = new Item(); break;
}
if (actor != null) addObject(actor, i*gap, j*gap);
}
}
} import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class game here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class game extends MainWorldClass
{
int[][] myTwoDArray = {
{0, 0, 0, 0, 0},
{2, 0, 1, 0, 2},
{0, 0, 0, 0, 0}
};
//gets height of a 2D array (it equals 3)
int height = myTwoDArray.length;
//gets width of a 2D array (it equals 5)
int width = myTwoDArray[0].length;
/**
* Constructor for objects of class game.
*
*/
public game()
{
super(myTwoDArray);
}
}
