i have rand limit 4
i want if a key is down then again i will get rand no.
so how will i do that
its not working properly
will i have to show the code or not????
//world //globally int rand =Greenfoot.getRandomNumber(2); A a =new A(); B b = new B(); public void act() { if(rand==0) { addObject(a,1,1); if(Greenfoot.isKeyDown("a"){ removeObject(a); int rand =Greenfoot.getRandomNumber(2); }} if(rand==1) { addObj(b,1,1); if(Greenfoot.isKeyDown("b"){ removeObject(b); int rand =Greenfoot.getRandomNumber(2); }} if(rand==2) { addObj(c,1,1); if(Greenfoot.isKeyDown("c"){ removeObject(c); int rand =Greenfoot.getRandomNumber(2); } }}
int rand; Actor[] objs = { new A(), new B(), new C() }; public void act() { String key = Greenfoot.getKey().toLowerCase(); if (key != null) { int n = "abc".indexOf(key); if (n == rand) { removeObject(objs[rand]); started(); } } } public void started() { rand = Greenfoot.getRandomNumber(objs.length); addObject(objs[rand], 1, 1); }
int rand; Actor[] objs = { new A(), new B(), new C() }; public void act() { String key = Greenfoot.getKey().toLowerCase(); if (key != null) { int n = "abc".indexOf(key); if (n == rand) { removeObject(objs[rand]); started(); } } } public void started() { rand = Greenfoot.getRandomNumber(objs.length); addObject(objs[rand], 1, 1); }