CECS 277 – Lab 7 Inheritance solution

$30.00

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (1 vote)

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.

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 (FlyingDragon.java) –
1. swoopAttack – 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 D12)
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 D12)
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 D12)
2. Sword (2 D6)
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 D12)
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 D12)
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 D12)
2. Sword (2 D6)
1
You hit the dragon with an arrow.
Congratulations Astrid!
You defeated all three dragons.
You win!