You may have to check to see if a rock is there first. Or (I don't know), maybe being on or under the rock might make you less prone to be infected.
public class InfectWorld extends World { /** * Constructor for objects of class InfectWorld. * */ public InfectWorld() { super(13, 13, 60); prepare(); } Greenfoot.setSpeed(identifier expected)(25); /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { Rock rock = new Rock(); addObject(rock, 5, 4); Rock rock2 = new Rock(); addObject(rock2, 8, 5); Rock rock3 = new Rock(); addObject(rock3, 5, 8); Rock rock4 = new Rock(); addObject(rock4, 2, 9); Rock rock5 = new Rock(); addObject(rock5, 9, 9); Rock rock6 = new Rock(); addObject(rock6, 10, 6); Rock rock7 = new Rock(); addObject(rock7, 7, 3); for (int uninf = 0; uninf < 36; uninf++) { int myX = Greenfoot.getRandomNumber(15); int myY= Greenfoot.getRandomNumber(13); UnInfected uninfected = new UnInfected(); addObject(uninfected, myX, myY); } addObject(uninfected8, 5, 2); InfectLv1 infectlv1 = new InfectLv1(); addObject(infectlv1, 11, 1); InfectLv2 infectlv2 = new InfectLv2(); addObject(infectlv2, 13, 3); } }
/** * Check to see if can be infected from Lv1 */ public boolean infect() { if(Image) =ppl3.png; {return false;} else{ return ((getObjectsInRange(5, InfectLv1.class)).size() != 0); } }
Rock rock = new Rock(); addObject(rock, myX, myY);
addObject(new Rock(), myX, myY);
// test for outside border if (x >= myWorld.getWidth() || y >= myWorld.getHeight()) { return false; } else if (x < 0 || y < 0) { return false; } List rocks = myWorld.getObjectsAt(x, y, Actor.class); if(rocks.isEmpty()) return true; else { return false; }
// test for outside border if (x >= myWorld.getWidth() || y >= myWorld.getHeight()) { return false; } if (x < 0 || y < 0) { return false; } // test for Actors return ((myWorld.getObjectsAt(x, y, Actor.class)).size() == 0);
public void act() { if(canMove()) { move(); } else { turnRandom(); } {getinfected(); } {getinfected2(); } }
public void act() { if(canMove()) { move(); } else { turnRandom(); } getinfected(); getinfected2(); }
private boolean gotInfected = false;