Hello,
I have a monster class. In it are Monster-Blue and Monster-Yellow. I want to spawn a monster from it.
I would say to Java: "Spawn me an object of the superclass Monster"
How have I to program it?


1 | getWorld().addObject( new Monster(), x, y); |
1 2 3 4 5 6 7 8 9 | int g = Greenfoot.getRandomNumber( 20 ); if (g == 10 ) { getWorld().addObject( new Monster-Blue(), x, y); } if (g == 20 ) { getWorld().addObject( new Monster-Yellow(), x, y); } |
1 2 3 4 5 6 7 8 9 | int g = Greenfoot.getRandomNumber( 20 ); if (g == 10 ) { getWorld().addObject( new Monster-Blue(), x, y); } if (g == 20 ) { getWorld().addObject( new Monster-Yellow(), x, y); } |