Question: PART A In Part A , you will design and implement the upgrade system of an action - adventure game. Use the following class diagram

PART A
In Part A, you will design and implement the upgrade system of an action-adventure game.
Use the following class diagram to implement the new Item. The player can also pick up and add
enhancements to increase the damage and durability of their weapon.
damage durability
Weapons:
Sword 21
Enhancements:
Iron +1+1
Gold +1+2
Diamond +2+1
Magic +3+3
energy
Food:
Bread +1
Ham +2
Pizza +3
1. Decorator Pattern
a. Draw the sequence diagram for the display of the weapon stats for a sword that equips
gold, iron, iron, and magic. Assume that the player is presented with these items in
that order.
b. Implement the design.
i. Complete the code with the Player class (with any other required
fields/methods), and required classes of the Items hierarchy.
- Starter code provided: Item interface
ii. Program a simulation of your system in use. Create a driver class named
Game2Driver that illustrates the upgrade system in gameplay.
- The game simulation starts with the player with 1 health and no weapon (sword
is null, but can be the first item the player picks up).
- Present random items (food and enhancements) to the player
An additional poison item may be presented to the player: the game
ends if the player picks it up
- The player will decide if they want to use each item
- Update and display the health and weapon stats as applicable
Notes:
- Weapons can have unlimited enhancements and stats
- Consider using JOptionPane for player input using showConfirmDialog e.g.
result = JOptionPane.showConfirmDialog(null, enhancement +" :
pick up?",null, JOptionPane.YES_NO_OPTION);
- Observer pattern and HUD/achievements from Assignment 1 are NOT required. You
can simply print from the Player class and/or driver to achieve the updates.
*** BE SURE TO COMMIT ALL YOUR CHANGES BEFORE MOVING ON TO PART 2***
2. Adapter Pattern
Add a new feature to your system: the ability to use a Food item as a weapon! When the
player first encounters the ham, the system will give them the option to equip it as a weapon.
From there, the player can add enhancements to their new ham weapon.
This new feature will use the Adapter pattern, where the adaptee is the Food interface.
a. Add a new class FoodAdapter to the class diagram that implements the methods of
the Weapon class with the intent for the food item (ham) to be used as a concrete
weapon (you can simply draw a segment of the class diagram, that represents this
pattern)
b. Add the sequence diagram for when the player first picks up a ham, and then chooses
to use it as a weapon (see d. below and sample output)
c. Implement your new feature.
- Add the applicable methods to the FoodAdapter where the food items
damage corresponds to the foods energy, and the durability is 0.
- In the Player class, include the new field e.g. hamWeapon
of type Weapon, and any applicable methods required for your simulation.
d. Update the game simulation to include your new feature. When the player is
presented with a special item, they are given the choice to add it as a new weapon.
After it is assigned as the SpecialWeapon, the player can choose to upgrade it with
enhancements found in the world. After equipping it as a weapon, any other special
item (e.g. ham) found in the world will only be consumed for energy.
Notes:
- Consider using JOptionPane for choosing between sword and ham with
showOptionDialog e.g.
String[] buttons ={"sword", "ham"};
JOptionPane.showOptionDialog(null, "Select the weapon to
enhance: ", null,JOptionPane.DEFAULT_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, buttons, buttons[1]);
- Test to make sure that the getDescription() provides a meaningful string of the layers of
decorators e.g. magic, iron, sword

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!