Requirements for the Second Phase Replace the random plant generation with user activity. Add buttons for the plants. These should show the kind of plant and the cost of a new plant of that type. Add...


Requirements for the Second Phase



  1. Replace the random plant generation with user activity.

    1. Add buttons for the plants. These should show the kind of plant and the cost of a new plant of that type.

    2. Add a resource, like the sun in the original game. This can be something that just grows over time (like adding gold each time step), or you can be more like the actual game and make it something that needs to be clicked on to be collected. Add a label showing the amount of resource available and update the label as more resource is gathered. Make sure the value shown in the label is neatly formatted.

    3. When a plant button is clicked, the next click should be on the game panel to see where to place the plant. You can decide what should happen if you click on another button instead or somewhere a plant cannot be placed. If there is not enough resource to "buy" a plant, do not allow it to be placed.

      1. Calculate the col and row the click is in, then place the plant in a cell. Check to see if the cell is empty. Do not place the plant on top of another plant (you can decide if you want to be able to place a Plant where a Zombie is). Align the plant to the cell. Deduct the cost of the plant from the resource (this can be done when the button is pressed or when it is placed).

      2. As a suggestion to how to structure this - use a listener on the plant buttons. Set some value if a button is pressed (think of how you stored rock-paper-scissors in that game). Use a mouse listener on the game panel. If the panel is clicked, check to see if the value storing a plant type is set and then try to place the plant.



    4. You will need to think about structuring the panels of the game. In the Battle project, you used multiple panels. You may want to do something similar here. It is easy to get a little confused about which panel the mouse listener is working on and what panel has the plants and zombies and what has the buttons. Draw some pictures. Stay organized and clear thinking. Some advice:

      1. The current Example JPanel draws the field and plants and zombies and listens for events. It currently does not have any UI components, like buttons on it.

      2. Make a JPanel with some buttons and labels in it. Add it to the Example JPanel. Use a layout manager to push it to the top or side or where you want the buttons.

      3. The panel with buttons will cover part of the field. Use the offset in the math of placing plants and zombies and calculating mouse clicks to push the drawn material away from the buttons.





  2. Make two derived Plant types and two derived Zombie types. One of each can be something simple, like fast or armored (so like you did for the plants in part 1 with just a custom class with a constructor). The other must override some super class method to allow more interesting behavior (for example, override attack, move, collision, or removeAction). As mentioned before, this cannot be a Healer type as done in lab. So there must be at least one interesting override of a method in one of the plant subtypes and one of the zombie subtypes. Your creativity matters here.

  3. Change the random Zombie appearance so that the two new subclasses of Zombie are used. If you use the random number compared to a threshold value idea from lab and do that twice, you can make each appear at different rates.

  4. If the Zombie makes it to the left side of the screen, the game is over. You can check the coordinates of the Zombie types to see where it is on the window. The game should freeze at this point or somehow change to show the end of the game. You are welcome to add a "game over" sprite on the screen.

  5. Add something to increase the difficulty as the game goes on - levels, types of zombies, rate of generation.


For phase 2, write up a short document explaining your types of plants and zombies and how the game gets harder. Make sure to describe the special behavior of each plant and zombie and what you had to do to implement it.

Nov 30, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here