![]() You can do this using a method from the rocket’s object menu. Play again (with at least two asteroids) to try it out.įrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.11 Once you have managed to remove all asteroids (or at any other point in the game), stop the execution (press Pause) and find out how many shots you have fired. (This should make getting the asteroids a bit easier!) Place a rocket into the world, and then invoke its setGunReloadTime method (through the object menu), and set the reload time to 5. Let us tweak our spaceship firing software a bit so that we can shoot a bit quicker. Vector is a helper class used by other classes From Introduction to Programming with Greenfoot by Michael Kölling Used with permissionįrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.10 If you have played this game for a while, you will have noticed that you cannot fire very quickly.Asteroid, Bullet and Rocket are subclasses of Mover.Explosion and Mover are subclasses of Actor.Space is a specific Greenfoot World - a subclass of World.Space represents specific world for the scenario.What does this do?įrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.8 What is the difference between clicking the Act button and invoking the act() method? (Try with several wombats in the world.) Exercise 1.9 Click the Run button. Exercise 1.7 Still with a wombat and some leaves in the world, click the Act button in the execution controls near the bottom of the Greenfoot window. What does this method do? How does it differ from the move method? Make sure to try different situations, for example, the wombat facing the edge of a world, or sitting on a leaf. ![]() What happens when you type a number greater than 3? What happens if you provide input that is not a whole number, such as a decimal number (2.5) or a word (three)?įrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.6 Place a wombat and a good number of leaves into the world, and then invoke a wombat’s act() method several times. Which number corresponds to which direction? Write them down. Provide a parameter value and see what happens. setDirection method:int direction indicates method requires 1 integer parameter to run From Introduction to Programming with Greenfoot by Michael Kölling Used with permissionįrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.5 Invoke the setDirection(int direction) method.One or more parameters – additional information required to run.Empty – needs no additional information to run.Parentheses hold the parameter list – additional information to run.Can you create a situation in which the result of this method is not zero? (In other words: can you make your wombat eat some leaves?) Does it always return true? Or can you find situations in which it returns false?įrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.4 Using a newly created wombat, the getLeavesEaten() method will always return zero. boolean – true or false From Introduction to Programming with Greenfoot by Michael Kölling Used with permissionįrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.3 Invoke the canMove() method on your wombat.Any other word indicates information that is returned.void returns nothing – completes task and stops.Return type indicates what the method returns to us.Place two wombats in your world and make them face each other. Invoke a method by selecting it from the menu From Introduction to Programming with Greenfoot by Michael Kölling Used with permissionįrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.2 Invoke the move() method on a wombat.Interact with objects by right-clicking them.From Introduction to Programming with Greenfoot by Michael Kölling Used with permissionįrom Introduction to Programming with Greenfoot by Michael Kölling Used with permission Exercise 1.1 Create some more wombats in the world. New Wombat objects can becreated by selecting the new option.Right-click on the Wombat class to see class menu. ![]()
0 Comments
Leave a Reply. |