@Entity1037 Ok, thank you
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 mainWorld extends World { private String[][] world; public mainWorld(String[][] array) { world = array; } public void setItemsFromArray(String[] world) { for (int i = 0; i < world.length; i++) for (int j = 0; j < world[i].length; j++) { if (world[i][j].equals("x")) addObject(new Player(), i * 5, j * 5); if (world[i][j].equals("y")) addObject(new Enemy(), i * 4, j * 4); } } }
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class world here. * * @author (your name) * @version (a version number or a date) */ public class game extends mainWorld { int[][] myTwoDArray = { {1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15} }; //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 world. * */ public game() { super(myTwoDArray); } }
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 Food(); break; } if (actor != null) addObject(actor, i*gap, j*gap); } }
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) { world = array; super(800, 400); } 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 { /** * Constructor for objects of class game. * */ public game() { 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; super(myTwoDArray); } }