greenfoot - Testing if random number equals a specific number -
i know might have been answered, places found it, wouldn't work properly. i'm making game in greenfoot , i'm having issue. i'm generating random number every time counter reaches 600, , testing if randomly generated number equal 1, , if is, creates object. reason, object created every time counter reaches 600. i'm new java it's simple.
import greenfoot.*; import java.util.random; /** * write description of class level_one here. * * @cuddlyspartan */ public class level_one extends world { counter counter = new counter(); /** * constructor objects of class level_one. * */ public level_one() { super(750, 750, 1); prepare(); } public counter getcounter() { return counter; } private void prepare() { addobject(counter, 150, 40); ninad ninad = new ninad(); addobject(ninad, getwidth()/2, getheight()/2); fail fail = new fail(); addobject(fail, greenfoot.getrandomnumber(getwidth()), greenfoot.getrandomnumber(getheight())); } private int spawncounter = 0; private int invinciblecounter = 0; random random = new random(); private int randomnumber; public void act() { controls(); {if (spawncounter > 500) { spawncounter = 0; addobject(new fail(), greenfoot.getrandomnumber(getwidth()), greenfoot.getrandomnumber(getheight())); } spawncounter++; {if (spawncountertwo > 300) { spawncountertwo = 0; addobject(new aplus(), greenfoot.getrandomnumber(getwidth()), greenfoot.getrandomnumber(getheight())); } spawncountertwo++; } if (invinciblecounter > 600) { int randomnumber = random.nextint(10); if (randomnumber == 1) { invincible invincible = new invincible(); addobject(invincible, greenfoot.getrandomnumber(getwidth()), greenfoot.getrandomnumber(getheight())); invinciblecounter = 0; } if (randomnumber == 2) { storm storm = new storm(); addobject(storm, greenfoot.getrandomnumber(getwidth()), greenfoot.getrandomnumber(getheight())); } else { } } invinciblecounter ++; } } private int spawncountertwo = 100; public void controls() { if (greenfoot.iskeydown("escape")) { greenfoot.stop(); } } }
i'm not getting errors compiling fine, when run have issues. help? in advance!
this speculation, since cannot see rest of code, suspect seeding random number generator constant number. every time run program, random number generator generates numbers in same order. in order confirm this, please show more code.
also, brackets not match, @ least please show enough code have matching curly braces.
Comments
Post a Comment