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????


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | //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 ); } }} |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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 ); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 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 ); } |