Hey, I'm having troubles trying to call some of the methods in "Scoreboard subclass" to my "Person subclass". I manage to do it passing a parameter in the constructor of "Person (<parameter>)" and a couple of other things, but I need to call those methods without having a parameter in the constructor (Person). So, What I'm going after is having no parameter in "Public Person()" but to use the methods inside the subclass Scoreboard.
----------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public class MyWorld extends World { private Scoreboard tab; public MyWorld() { // Create a new world with 800x600 cells with a cell size of 1x1 pixels. super ( 800 , 600 , 1 ); tab = new Scoreboard(); // creates the Scoreboard addObject(tab, 399 , 10 ); // add the Scoreboard to the World Person player = new Person(tab) ; // creates a new player addObject(player, 2 , 580 ); // add the player to the World Spider Enemy = new Spider(); // create a new Spider object addObject(Enemy,Greenfoot.getRandomNumber(getWidth()), 54 ); // add the object to the world } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class Person extends Actor { private Scoreboard tablero; public Person (Scoreboard tab) { tablero = tab; keyBoard = "space" ; if (Greenfoot.isKeyDown( "space" )) { getWorld().addObject( new Trap(), locatX, locatY); } } |