Goals The goals of this assignment are to: See how inheritance and polymorphism aid development of more complex projects To practice writing classes that fit into a larger structure To develop an...


Goals


The goals of this assignment are to:



  1. See how inheritance and polymorphism aid development of more complex projects

  2. To practice writing classes that fit into a larger structure

  3. To develop an event-driven program

  4. To use elements of a GUI


These concepts will be developed in the context of a Plants vs. Zombies game. You can see the original game at



https://www.pogo.com/games/plants-vs-zombies?gamekey=plants-vs-zombies#game(Links to an external site.)


(You may have to enable Flash to get it to start).


Getting Started


Begin by downloading thisa10 package
(Links to an external site.). It is close to what is used in the lab, but with more comments and a few added classes and methods. There is also some sample art. Finally, there is a test program, Example.java, that runs a zombie at a plant. Make sure that runs.


Do your work in this package.


Assignment Requirements



  1. Decide a theme that is plant vs zombie-like but of your own creation. You should consider if you can find any images to use as characters in the game. You can also draw your own. For example, you can usehttps://www.piskelapp.com(Links to an external site.)to draw and save simple sprite images. Using images you find is probably the easier way.

  2. To the example code, add rows for zombies to appear in. You should use a random number to pick a row, and use ideas from the Whack-a-Zombie lab to position a zombie in a row.


    1. Have zombies appear on the right side in the rows

    2. Zombies should move left until they encounter a plant. The zombie should attack the plant until the plant health is

    3. Plants should attack zombies that are touching them. Zombies with 0 health should be removed.



  3. Add a sub-class that inherits from Zombie. Override one of the Zombie or Actor methods to give it a new behavior (a different style of attack or movement, for example - be creative!). This zombie type should have a different image from the basic zombie.

    1. Use a random number to add this kind of zombie to the game along with the random number to add the basic zombie. They can appear at different rates by using different threshold values in the if statements.



  4. Add a sub-class that inherits from Plant. Override one of the Plant or Actor methods to give it a new behavior (a different style of attack or movement, for example - be creative!). This plant type should have a different image from the basic plant.

  5. Make the game stop if a zombie makes it to the left side of the screen. You can compare screen coordinates with the zombies to see if it has reached the left side.

  6. Add user interface elements to give the player some control. Add

    1. Buttons for each kind of plant. When a button is clicked, wait for a click on the game frame and add the correct plant there.

      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 add a plant to a location that already has a plant in it. Align the plant to the cell. Checking for an empty cell and aligning to the grid is like the Whack-a-Zombie lab. For the click on a button and then click on the scene to place, consider:

        1. Use a listener to detect mouse clicks.

        2. Decide if the click happened on a button or on the field.

          1. If it is a button, store the kind of plant that was selected

          2. If the field, see if there is a stored plant type and add it to the field.





      2. Add a label that shows a resource amount that can be used to buy a plant. Make the resource grow every time the game loop updates. Give each plant a cost, and check if there is enough resource to buy a plant before you can select it with a button.

      3. Think about what the appropriate behavior should be if a person clicks on one plant then the next button without clicking on the field or if they click on a plant button and do not have enough resource.





  7. Add something to increase the difficulty over time - levels, types of zombies, rate of generation.


Write up a short document explaining the theme of your game, the new behaviors for your custom Zombie and Plant, and how the game gets harder. Make a short video of the game in action (capture with a phone or software on your computer). Submit a zipped folder of your code, any images, the video, and the pdf of the document to gradescope.



Apr 21, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here