Philip Yuan
This is the UML Diagram for the project.
Click on the image to view it alone.
// #19 - UML Diagram
This program is intended to simulate a group of video game characters. At the top of the hierarchy is the GameCharacter class, as all the video game characters are GameCharacters. Because all video game characters must have a position and a direction relative to that position, the interface Position is implemented in GameCharacter. Then there are two subclasses of GameCharacter (a is-a relationship) - Mario and Enemy. Enemy is simply a default character with only position and direction, but it has a more complex String output when its getDirection() method is called, so it is used to demonstrate polymorphism. Mario has additional methods that GameChracter doesn't have, with an inventory and the ability to attack. This inventory is made of InventoryItem objects; that is, Mario has-a InventoryItem. MarioDriver demonstrates all the methods of the above classes and interfaces.
GameCharacter is the superclass for this project. It contains what all characters must have, a position and a name.
Mario is a subclass of GameCharacter; it is-a GameCharacter. It contains additional items a default GameCharacter does not have, such as an inventory full of items and the ability to attack.
InventoryItem shares a has-a relationship with Mario; Mario has-a InventoryItem. An ArrayList of these is used in Mario to define the inventory.
Enemy is a subclass of GameCharacter; it is-a GameCharacter. It represents an enemy, who is just a GameCharacter with an overriden getDirection() method. In the driver, polymorphism is used with this class.
Position is an interface implemented in GameCharacter. It shows that a GameCharacter must have a position and direction.
MarioDriver is the driver for the whole program. Run this to test the methods, with some results in the implementation section.