DO NOT COPY THIS LINE - START static code example DO NOT COPY THIS LINE - START CrabWorld 2 new variables static boolean lobsterSuperPower; // stores if lobster superpower on or off (true or false) int superNumber = 20; // the number of worms left in the world at which the lobster superpowers will be activated. DO NOT COPY THIS LINE - START at bottom ofCrabWorld class - 2 new methods // method to set the boolean type variable lobsterSuperPower to true or false depending on what is passed into the method public void setLobsterSuperPower(boolean iPower) { lobsterSuperPower = iPower; } // method to return a boolean value (true or false) whether the lobster has its superpowers activated public static boolean lobsterHasSuperPower() { return lobsterSuperPower; } DO NOT COPY THIS LINE - START in CrabWorld constructor method (at the end of the constructor) setLobsterSuperPower(false); DO NOT COPY THIS LINE - START in CrabWorld act method (towards the end of the method but within the win/lose if conditional block of code i.e. before the } for this if conditional) if (!lobsterHasSuperPower()); { if (numWormsLeft <= superNumber) { setLobsterSuperPower(true); } } DO NOT COPY THIS LINE - END CrabWorld code DO NOT COPY THIS LINE - START Lobster new code DO NOT COPY THIS LINE - START in act method after right and left turn if conditional code blocks // Only allow controls for additional "super" powers if they have been // switched on in the Crabworld act() method lobsterHasSuperPowers() is a // static method therefore we can call it using CrabWorld.lobsterHasSuperPower() // as it exists at Class level, not object level if (CrabWorld.lobsterHasSuperPower()) { // if the up keyboard arrow key is pressed then sprint if (Greenfoot.isKeyDown("up")) { move(10); } // if the down keyboard arrow key is pressed then turn around if (Greenfoot.isKeyDown("down")) { turn(180); } } DO NOT COPY THIS LINE - END non-static code example DO NOT COPY THIS LINE - START non-static code example DO NOT COPY THIS LINE - START CrabWorld class - remove the static keyword from the variable lobsterSuperPower and the method header lobsterHasSuperPower DO NOT COPY THIS LINE - START Lobster class - in act method after right and left turn if conditional code blocks // Only allow controls for additional "super" powers if they have been switched on in the Crabworld act() method // The Lobster object does not actually know what World it has been created into, // so if we want to use/call a method in that World (or in this example CrabWorld) then // we have to first find the World object that our current animal object (Lobster) exists in. // We use the method getWorld() which is in the Actor class, which will return the name of the world object that the Lobster object exists in. // An added issue here is that the getWorld() method assumes that the World Object name returned will be of Type World (not type Crabworld, which we know is a subclass of World) // Therefore if we use the code -- if (getWorld().lobsterHasSuperPower()) - this will fail when compiled as the method lobsterHasSuperPower() is in the CrabWorld subclass, not the World class. // So we must ensure that the world returned from getWorld() must be of CrabWorld type! // We do this by using something called casting or typecasting in Java, where we "cast" CrabWorld onto the getWorld() method so that the getWorld() method knows // that it is returning a world object of the type "CrabWorld" therefore allowing the lobsterHasSuperPower() method to be found in CrabWorld and called. // Why do it this way? lets say you have multiplpe levels in a game and each level is an object of World (or CrabWorld in this example) where an actor (or animal in this example) objects exist!, // this method will allow your actor (or animal in this example) object to be able to find out which world they exist in, allowing them to interact with it. if (((CrabWorld)getWorld()).lobsterHasSuperPower()) DO NOT COPY THIS LINE - NOTE: this if conditional above replaces the if conditional further above that uses the static referencing of lobsterHasSuperPower method (i.e. if (CrabWorld.lobsterHasSuperPower()) DO NOT COPY THIS LINE - END non-static code example