![]() Game ends when the Crab is caught by the Lobster.This method makes the crab turn left (-4 degrees) or right (4 degrees) depending on the key that is pressed.Įnding the Game From Introduction to Programming with Greenfoot by Michael Kölling Used with permission Create another method called checkKeyPress which is called from the act method. Exercise 3.19: Remove the Random Turning and the Turn at Edge coding. To keep a copy use Save a Copy As from the Scenario menu. From Introduction to Programming with Greenfoot by Michael Kölling Used with permission Greenfoot automatically saves classes and scenarios when their windows are closed. Method returns boolean thus it can be used in an ifstatement.“left” for the left cursor key (arrow).String is text which is enclosed in quotes “.Signature is: static boolean isKeyDown(String key).Greenfoot has method to check if a key on the keyboard has been pressed.Keyboard Control From Introduction to Programming with Greenfoot by Michael Kölling Used with permission ![]() ![]() Does the crab manage to eat all the worms before it is caught by a lobster. Exercise 3.13: Copy the act method from the Crab class to the Lobster class replacing all references to Worm with Crab Exercise 3.14 Place a crab, three lobsters and many worms into the world. From Introduction to Programming with Greenfoot by Michael Kölling Used with permission Use ifstatement to determine if crab sees worm – condition true then crab eats worm if ( canSee(Worm.class) ) Īdding Lobster Actor From Introduction to Programming with Greenfoot by Michael Kölling Used with permission Lobsters like to eat crabs Exercise 3.10: Add new class (Lobster) to your scenario.
0 Comments
Leave a Reply. |