Hi! I've been in a programming class working with Greenfoot for about a month, and our first project is due next week. For reference, these are the instructions for the project:
Create a Car class that represents a car running horizontally back and forth.
1. Modify the Car class to make the car image displayed correctly when it runs towards left side.
2. Add code to Car class to catch the “down” key. When user presses down key once, it drops an apple, pear or banana from the top of the “world”. The position of the starting point of dropped fruit is random. Which fruit that is dropped is also random.
3. Create a Fruit class that represents apple, pear, or banana based on which image is picked. The speed of fruit moving down should be slow (so we can call method move(1) in act() method of Fruit class.
I'm having trouble with #2, in which I'm supposed to have the Car class catch the down key in order to drop the fruit. What should I do? The relevant code is as follows (The compiler stops at the Fruit class and says it does not recognize):
Thank you for your help!
String key = Greenfoot.getKey(); { if ("down".equals(key)); int x = Greenfoot.getRandomNumber(getX()); int y = 0; addObject(new Fruit(), x, y); }