CS218-Shark

Overview of the request

Fish Game: Create a fish game along the line of a classic game Shark! Shark!(http://www.youtube.com/watch?v=HiHTZ8wZ_Hc&feature=related).

In the classic game above, you start as a baby fish, growing by eating smaller fishes, and staying alive by dodging larger fishes.

In this request, we will create a fish game that is similar to but not exactly the same as this classic game – please always follow our requirements as specified below when they are different. You may use as much of your code from request 2 as you need. Before you start, take some time to plan your design.

This request is different from the last two and will require you think through things in advance. Use Inheritance, polymorphism, key-based interactions, ArrayList, and your knowledge of objects to write the code.

General Requirements& Learning Objectives

Learning objectives

  • Create application using inheritance and polymorphism;
  • Create key-based interactions;
  • Use ArrayList to store and remove objects;
  • Create dynamic text messages;
  • Create simple Graphical User Interface (GUI) using GUI library

Programming Requirements

First of all, this request must be done using Java System Library (e.g. using Graphics2D for drawing). You will get 0 if you use Processing library (e.g. using PApplet for drawing) or any other 3rd party libraries.

This request has two iterative steps: Milestone: initial UML design and code for drawing the fishes and Pond, and Final Deliverable: updated UML design and code for fishing For the UML design document, you are graded on completeness and correctness, and for the code on completeness and visual style.

For the UML design document, you are graded on completeness and correctness, and for the code on completeness and visual style.

MilestoneCode: Design Inheritance and Drawing Fishes and Sea

UML Design

Draw the initial UML that should include at least three classes to represent a general fish and two types of enemy fish: shark and herbivore fish (i.e. weed eating only). The enemy fishes must extend (i.e. be the subclasses of) the general fish, and meet the following requirements:

First of all, you need to design your classes by following strict Encapsulation for fields (except for constants), and provide public methods only when it’s absolutely necessary. When working with inheritance, you are allowed to relax access control of superclass’ fields from private to protected so as to facilitate subclasses to access some of these fields directly. As with public methods, you should relax access as such only when it is absolutely necessary.

About the general fish

a) The general fish class should hold properties common to both player fish and enemy fish, such as position (along x & y), velocity (along x and y), angle for rotation, etc.

b) The general fish should also have some methods that could be either used directly or overridden by its subclasses, such as drawFish(Graphics2D g2), detectCollision(), detectOffScreen(), etc.

c) Please note the whole purpose to have the general fish class is to use it as the superclass for player fish and enemy fish, you shouldn’t instantiate any object of it.

About the enemy fishes

d) For the herbivore fish, you can basically use the fish that you have created in request 2 with modifications. For instance, you need to redesign the code structure to accommodate inheritance, so that it will make use of the fields and methods of the general fish while declaring its own fields such as field for body color.

e) It must override at least drawFish(Graphics2D g2) method of the general fish, to allow it to draw enemy fish using the color held in the field of body color f) For the shark, you need to redesign a new fish that is visually in the form of shark, which must has tail that is visually obvious. Beyond inheriting the common properties of the general fish, the fish must have the capability to eat other types of fish, including the herbivore fish and player fish (included in the final deliverable)

g) A shark can eat other fishes only when it is facing them and close to their mouth (i.e. in head-on position), so you need to have a method to check on this.

h) Design FishPanel class and aggregate an ArrayList of general fish. Then add as field a Timer object.

i) Create FishApp class as a subclass of JFrame, and associate it with the FishPanel class.

j) The UML diagram must follow the UML notations for class and encapsulation. Also the names of the class, fields and methods must follow the naming convention with appropriate upper- or lower case for the initial and CamelCase thereafter.

(Please note the structure of your code must match your UML design. Otherwise you will lose credit for the UML design)

Coding per the design:

a) you should use the whole display window to represent the sea, leaving no margins for any of the sides.

b) You must use an ArrayList of general fish to hold the enemy fishes, among which two of them should be sharks and the rest herbivore fish.

c) The sharks initially should be in uniform color and size (it should be equal to or slightly larger than the upper bound of herbivore fishes’ sizes), while the herbivore fishes must be in randomized colors and sizes.

d) An herbivore fish is eaten by a shark when they go head-on (i.e. face to face with mouths being close) and grow itself proportionally to the size of the fish eaten. Otherwise they bounce off from each other.

e) Herbivore fishes must bounce off each other when they collide and NO eating happen among themselves.

f) The enemy fishes must move left and right in the sea, with wavy (up and down) movement based on the sin or cos function.

g) When an enemy fish fully goes off the screen or when it is killed, it must be destroyed (i.e. removed from the ArrayList).

h) Enemy fishes should be respawned at a steady interval for up to a maximum of 10 including no more than 8 herbivore fishes and no more than 2 sharks on the screen (you should spawn one fish for each interval, and use a random function call to give 80% of chance to herbivore fishes and 20% chance to shark). Respawned fishes should move in randomly from either left or right side of the window.

Final deliverable: Fish Game

Update the UML design to include

a) Class for player fish (avatar), which is a subclass of general fish as well, and must include at least two unique visual features (e.g. dots, stripes etc.) as represented by geom objects so that it will be easy to distinguish it from those herbivore fishes.

b) The player fish must override at least the drawFish(Graphics2D g2) method of general fish to draw it differently.

c) An inner class (you can download the membership notation from Canvas|Resource and used it in the UML to indicate the nested relationship), which extends KeyAdaptor class for key interaction per the features for gameplay below.

d) GUI features as outlined below.

(Please note the structure of your code must match your UML design. Otherwise you will lose credit for the UML design)

Coding per the design

About the player fish.

a) The movement of the player fish must be controlled by key inputs.

b) The player fish would grow by eating an herbivore fish smaller than itself, and the growth must be proportional to the size of the fish eaten.

c) If it however tries to eat an herbivore fish that is greater than itself, it will be killed, and before it runs out of its lives it respawns at a location within the screen, which meets the digit-based requirements as specified.

d) Eating can happen ONLY when the player fish and an enemy fish go in head-on position as outline in the milestone part.

e) Whenever eating happens (no matter player fish eats enemy fish or vice verse), certain bubbles or traces should be displayed as per the digit-based requirements as specified.

f) Player fish can kill a shark by touching its tail 4 times before it moves out of the screen. If however it touches on the shark any part other than the tail, it will be killed instantly.

g) When a shark is touched by its tail it must flash with a different color to demonstrate the effect, and when it is killed, it must change its shape in certain way to show that it is dead while sinking to the bottom of the sea (refer to Shark! Shark! for example but you can have your own appropriate form)

About Style

As always, visual Design Matters! Grades will partially depend on how the game looks, including sea design with appropriate, animated decoration objects, animated fish features for enemy fishes and player fish, the HUD (e.g. using fish images rather number to show number of lives, and nicely designed score board). Beyond this, there are some specific requirements as follows based on your student number.