Tino Intro To Java

Last modified: June 02, 2023

Greenfoot Final Practice

Demo

Here is a Demo Project showing how the program works.

The demo does not actually create any objects in the world. Instead, you need to right click on the class you want to test and create a new Intance of that class. You can also select the class and then shift click on the world. Once you have added some objects, you can press run. Try clicking on the objects to select them and press space to see what happens to the ones you have selected. Try making another object touch a Cactus.

Instructions

  1. Create a greenfoot project named in the format PX_LastName_FirstName_FinalPractice
  2. Write a Tile class to represent tiles. You can pick any image.
  3. A tile keeps track of whether it is selected or not and modifies its image to indicate if it is selected. You should have a getter and setter to access and change the status of being selected.
  4. The setter should not only change the selected status, but also update the image by drawing a red border around the image if it is selected.
  5. Since it will be modifying its image, it is important to keep a copy of the original unmodified image. There should be a setter and getter for the variable holding the original image. 6. Note that the setter should also update the actual image of the tile.
  6. Tiles also have an action that is performed whenever space is pressed and the tile is selected. If a tile is not selected, it does nothing when space is pressed.
  7. Every frame, a tile should check if it was clicked on and if so, it should toggle its selected status.
  8. Every frame, if the space key is pressed, a tile should execute its action if it is selected. The action is defined in the onAction() method. For the top level Tile class, onAction() will do nothing, but subclasses will override onAction() to perform other actions.
  9. Make a subclass of Tile named Banana. A banana should override the onAction() method to move down by one cell whenever onAction() is called.
  10. Make a subclass of Tile named Lemon that removes itself from the world whenever it performs its action.
  11. Make a subclass of Tile named Cactus that marks images selected by filling a rectangle covering the whole image with a green rectangle that is partially transparent (alpha 100).
  12. When a cactus touches another tile, it should call onAction() on the other tile.

Right click on the classes and create new instances of them and then click on the world to place them where you want to test out the program. Zip your project and submit to this form. name your zip file in the form PX_LastName_FirstName_FinalPractice.zip.

You must Sign In to submit to this assignment

Dark Mode

Outline