Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a game where the user must defeat three dragons to pass the trials. Use inheritance to implement the following class diagram in your program.

Create a game where the user must defeat three dragons to pass the trials. Use inheritance to implement the following class diagram in your program. Java code please.image text in transcribed

Here is output:

image text in transcribed

CECS 277 Lab 6 Dragon Trainer Create a game where the user must defeat three dragons to pass the trials. Use inheritance to implement the following class diagram in your program. FireDragon Dragon - int fireShots - String name + Fire Dragon(String n, int mHp) - int hp + int fireShot) - int maxHp + String toString() + Dragon(String n, int mHp) k + String getName() + int getHp0 Flying Dragon + int attack + void takeDamage(int d) - int swoops + String toStringo + FlyingDragon(String n, int mHp) + int swoop Attack + String toStringo Dragon Class (Dragon.java) - 1. Constructor - pass in the dragon's name and starting hit points. Assign the mHp value to maxHp and hp. 2. attack return a random amount of damage in the range 3-7. 3. takeDamage - pass in an amount of damage, subtract this value from the dragon's hp. If the hp value is less than zero, reset it to 0. 4. toString - display the dragon's name and hp (hp/maxHp). Fire Dragon Class (FireDragon.java) - 1. fireShot - if a fire dragon has any shots left, then return a random number in the range 5- 9, otherwise return 0. Decrement the number of shots if one is fired. 2. toString display the name and hp (by calling super), and the number of shots left. Flying Dragon Class (Flying Dragon.java) - 1. swoop Attack - if a flying dragon has any swoop attacks left, then return a random number in the range 5-10, otherwise return 0. Decrement the number of swoops after a swoop attack is done. 2. toString - display the name and hp (by calling super), and the number of swoops left. Main Class (Main.java) - Create one of each of the dragons and give the user some hit points. Allow the user to choose which dragon to attack (if they have any hp). Allow the user to choose to attack with an arrow (random 1-12) or with a sword (random 1-6 + random 1-6). Do that much damage to the dragon they chose to attack. Then choose a random (living) dragon to attack the user. If it is a fire or flying dragon, randomly choose to do a regular attack or their special attack. Do that much damage to the user. Repeat this process until the user defeats all three dragons, or the user dies. Check that all user input is valid. Javadoc all methods. Example Output: What is your name, challenger? Astrid Welcome to dragon training, Astrid You must defeat 3 dragons. Astrid HP: 50 1. Attack Deadly Nadder: 10/10 2. Attack Gronckle: 15/15 Fire Shots remaining: 3 3. Attack Timberjack: 20/20 Swoop attacks remaining: 5 1 Attack with: 1. Arrow (1 012) 2. Sword (2 D6) 2 You slash the dragon with your sword. Deadly Nadder smashes you with its tail. Astrid HP: 44 1. Attack Deadly Nadder: 7/10 2. Attack Gronckle: 15/15 Fire Shots remaining: 3 3. Attack Timberjack: 20/20 Swoop attacks remaining: 5 1 Attack with: 1. Arrow (1 012) 2. Sword (2 D6) 1 You hit the dragon with an arrow. Timberjack smashes you with its tail. Astrid HP: 40 2. Attack Gronckle: 15/15 Fire Shots remaining: 3 3. Attack Timberjack: 20/20 Swoop attacks remaining: 5 2 Attack with: 1. Arrow (1 012) 2. Sword (2 06) 2 You slash the dragon with your sword. Gronckle smashes you with its tail. Astrid HP: 37 2. Attack Gronckle: 4/15 Fire Shots remaining: 3 3. Attack Timberjack: 20/20 Swoop attacks remaining: 5 3 Attack with: 1. Arrow (1 012) 2. Sword (2 D6) 2 You slash the dragon with your sword. Gronckle spews fire at you. Astrid HP: 31 2. Attack Gronckle: 4/15 Fire Shots remaining: 2 3. Attack Timberjack: 11/20 Swoop attacks remaining: 5 2 Attack with: 1. Arrow (1 012) 2. Sword (2 D6) 2 You slash the dragon with your sword. Timberjack swoops down and knocks you over. Astrid HP: 21 3. Attack Timberjack: 11/20 Swoop attacks remaining: 4 3 Attack with: 1. Arrow (1 012) 2. Sword (2 D6) 1 You hit the dragon with an arrow. Congratulations Astrid! You defeated all three dragons. You win

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions