I'm making a game that has a percent chance to change the image of an actor if it is next to a certain actor. How do I do this?


1 2 3 4 | if (Greenfoot.getRandomNumber( 100 ) < 20 ) { // change the image here } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public boolean infect; { World theWorld = getWorld(); if (Greenfoot.getRandomNumber( 100 ) < 25 ) { setImage( "ppl2.gif" ); } List Uninfect = getObjectsInRange( 2 , InfectLv1. class ); if (Uninfect.isEmpty()) return false ; else { return true ; } |
1 2 3 4 | public boolean infect() { // code here } |
1 2 3 4 5 6 7 8 | if (Uninfect.isEmpty()) { return false ; } else { return true ; } |
1 | return !Uninfect.isEmpty(); |
1 | return !(Uninfect.isEmpty()); |
1 | return ((getObjectsInRange( 2 ,InfectLv1. class )).size() != 0 ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public boolean infect() { World theWorld = getWorld(); if (Greenfoot.getRandomNumber( 100 ) < 100 ) <set for 100 % { setImage( "ppl2.gif" ); } { return ((getObjectsInRange( 2 , InfectLv1. class )).size() != 0 ); } } |