Answer & Explanation:Program.docx
program.docx
program.docx
Unformatted Attachment Preview
1.0 Description:
This program simulates the battle between two character classes. In the HaveBattle class
we are having a battle between a Mage and a Warrior. You are to write the supporting code
using inheritance and a touch of polymorphism.
1.1 Characters
There are two types of CharacterClasses, Warriors and Mages. Each CharacterClass has
a currentHP, maxHP. Warriors also have an implicit armor that offsets 10 damage.
CurrentHP is the amount of health the character
currently has and the maximumHP is the amount of hit points a fully health character could
have.
All characters can deal damage (double dealDamage();) which calculated how much
damage they will
inflict on another player using their abilities and wepaons or spells. and they can receive
damage
(void receiveDamage(double amount);) A character is alive (boolean isAlive()) when
the currentHp is greater than zero. A character can also heal (void addHealth(double
newAmount))
this adds the amount of healing up to maximum HP.
There are two types of Characters. Mages and Warriors.
1.1.1 Mage
Mages have a spell book, and they also have mana (which is the amount of spell power they
have). Mana can be between a minimum of 0 and a maximum of 100. They also regenerate
mana (and hp’s) if they do nothing at an amount (for the sake of this example we can fix this
to 25 mana units and 10 hp’s and will continue to accumulate as long as the magician rests
(which they can do during a battle by doing nothing for a turn).
Mages can add spells to their spell book (void addSpell(Spell newSpell)). They can also
throw their spell book away and get a new one (void newSpellBook()).
Most importantly when in battle and the dealDamage method is called it will returns how
much damage is done to the enemy by the mage. In the case of the mage, the mage has
three options firstly if the mage’s mana is < 10 they will rest for the turn (which does/returns
zero damage). If the mage is < 30 hp's they will stop and cast a random healing spell from
their spell book. If they have no healing spells they should rest which will give them back 10
hps (as well as the mana regeneration) Else the mage will attack by selecting a random
TargetedSpell spell from their spellbook and casting that return the damage it inflicts on the
target. Note that while dealing damage the sound the spell makes is printed.
1.1.12 Warrior
Warriors are simpler they can have up to 5 weapons and are born with a weapon in their
hand. Like the mage they will deal damage but they are unencumbered by magic and have
a simpler algorithm for fighting. Simply they pick a random weapon and try to kill the enemy
with it. Again the sound the weapon makes is printed.
1.2 Effector
All spells and weapons affect a character. They have a name, a minimum effect and a
maximum effect. When an effect occurs it is randomly selected between minimum and
maximum effect. All Effector's make a sound.
1.2.1 Spell
Spells are a type of effector. There are two types of spells "HealingSpell" and
"TargetedSpell" They define the different types of spells that can be cast. Each of these
types have subclasses which are the Fireball, IceStorm and MinorHealing
1.2.1.1 TargetedSpell
For the sake of the exercise there should be at least 2 types of TargetedSpells
Fireball
•
•
•
•
Mana Cost 15
Minimum Effect 40
Maximum Effect 50
Sound:Crackle Boom
IceStorm
•
•
•
•
Mana Cost 20
Minimum Effect 50
Maximum Effect 60
Sound:Chatter Boom
1.2.1.2 Healing
For the sake of the exercise there should be at least 1 types of Healing Spell
MinorHealing
•
•
•
•
Mana Cost 20
Minimum Effect 40
Maximum Effect 40
Sound:Warble
1.2.2 Weapons
Weapons are another type of effector. All weapons have a calculateDamage method to
return the amount of damage the weapon did between minimum and maximum effect.
For the sake of the exercise there should be at least two types of weapon.
Axe
•
•
•
Minimum Effect 15
Maximum Effect 25
Sound:Clink
Sword
•
•
•
Minimum Effect 1
Maximum Effect 50
Sound:Wosh
1.3 Spellbook
The mage holds a spellbook which each page contains one spell. Spellbooks contain both
targetedSpells and Healing spells. Spellbook has two methods (getTargetedSpells and
getHealingSpells) which returns a list of all the spells of that type that are in the spell
book. This is necessary so that the mage can choose from either offensive or defensive
spells during the fight. To save you time this has been supplied to you below.
1.4 Log
To keep a record of these epic battles there is a centralized logging program for your
fight. This class will either output to the screen or to the disk depending on whether a
method is called. This class is supplied to you in skeleton below with only the screen output
working. You should extend this to allow the HaveBattle method call write to disk or write to
screen methods.
2 Your Mission
You are to take the description above and build the software to implement the code to run
the battle.
2.1 Requirements
Here are a list of requirements for your assignment.
•
•
•
•
•
•
•
•
•
•
•
•
HaveBattle class must work. This is designed to use your code.
You must use inheritance where appropriate
Push as much code up the inheritance structure as possible.
You must use abstract where appropriate
You should write some testing to make sure your assignment works. You don't need to
use junit however, whatever you write should do reasonable job of making sure your
assignment works.
A static method for generating a random number in a range is supplied in the effector
class skeleton. Feel free to use it.
Only import the needed classes in each class
Jpg image of your inheritance diagram called inheritance.jpg included in the project
txt file with your testing outline called testing.txt
Class javadoc, Method javadoc, Instance javadoc and method body commenting
16 classes should be included in your workspace. Don't panic quite a few of them are
only a few lines of code.
Whatever you submit it should be compilable and runnable even if it doesn't do
everything that is required.
2.2 Suggested Order
This is a suggested approach to doing your assignment.
1. Create the packages (base package of unisa.pf.assign02. then subpackages base,
characters, spells,
2. testing, util and weapons).
3. Draw up the inheritance structure using this document and supplied code to give you
clues.
4. Put the supplied code into classes into the appropriate packages.
5. Get the code commented and tested
6. Create the missing files and get it to compile (even with empty classes).
7. Get the code commented and tested
8. Work on the log.java file (this will work independantly).
9. Get the code commented and tested
10. Write missing methods so that the HaveBattle class will compile.
11. Get the code commented and tested
12. Get the program so it will call dealDamage and receiveDamage.
13. Get the code commented and tested
14. Get the dealDamage and receiveDamage methods to work (trickiest part)
15. Get the code commented and tested
2.3 Testing
You are to write a test outline of what you would test and how you would test it in your
program. It is not necessary to code this just include a textfile (testing.txt). You should put
in sections on each class and under each class each method and the test cases you would
test. You do not need to do junit testing for this assignment (I think you have enough to do
without writing all that).
3.0 Marking
This assignment will be marked on the following independant criteria
Number of Marks
10
10
5
15
15
10
20
15
Description
Commenting
Style
Inheritance Diagram
Inheritance Code
Logging System Implementation
Other Code
doBattle and receiveDamage methods
Testing Design
If the code doesn't compile/work the maximum marks you can receive is 40%
4.0 Supplied Code
Here is some code to get you going. You must use this code and you should also fully
comment the code.
4.1 Spellbook.java
(this code only needs commenting)
package unisa.pf.assign02.spells;
import java.util.Arrays;
import java.util.LinkedList;
public class SpellBook {
LinkedList pages = new LinkedList();
public Spell[] getTargetedSpells() {
LinkedList offensive = new LinkedList();
for (Spell i: pages) {
if(i instanceof TargetedSpell) {
offensive.add(i);
}
}
Spell[] returnVal = new Spell[offensive.size()];
for(int i=0;iwith Spell:IceStorm for 51.0 HP o
f damage:][Sound::Chatter Boom]Ashen-Shugar Ver(0) uses armor to reduce da
mage from 51 to 41. Remaining hp is 199
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 17.0 hp o
f damage:][Sound::Wosh]Macros the Black Ver(0) uses armor to reduce damage
from 17 to 17. Remaining hp is 103
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:IceStorm for 56.0 HP o
f damage:][Sound::Chatter Boom]Ashen-Shugar Ver(0) uses armor to reduce da
mage from 56 to 46. Remaining hp is 153
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 37.0 hp o
f damage:][Sound::Wosh]Macros the Black Ver(0) uses armor to reduce damage
from 37 to 37. Remaining hp is 66
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:Fireball for 42.0 HP o
f damage:][Sound::Crackle Boom]Ashen-Shugar Ver(0) uses armor to reduce da
mage from 42 to 32. Remaining hp is 121
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 23.0 hp of
damage:][Sound::Clink]Macros the Black Ver(0) uses armor to reduce damage
from 23 to 23. Remaining hp is 43
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:Fireball for 40.0 HP o
f damage:][Sound::Crackle Boom]Ashen-Shugar Ver(0) uses armor to reduce da
mage from 40 to 30. Remaining hp is 91
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 20.0 hp of
damage:][Sound::Clink]Macros the Black Ver(0) uses armor to reduce damage
from 20 to 20. Remaining hp is 23
+++New Turn+++
[[Mage Turn]]Magician Action: Regen Health -)Health Changed From 23 HP to
63 HP
with Spell:Minor Healing for 0 hp of damage: Sound[:Warble]Ashen-Shugar Ve
r(0) uses armor to reduce damage from 0 to 0. Remaining hp is 91
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 19.0 hp of
damage:][Sound::Clink]Macros the Black Ver(0) uses armor to reduce damage
from 19 to 19. Remaining hp is 44
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:IceStorm for 53.0 HP o
f damage:][Sound::Chatter Boom]Ashen-Shugar Ver(0) uses armor to reduce da
mage from 53 to 43. Remaining hp is 48
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 15.0 hp o
f damage:][Sound::Wosh]Macros the Black Ver(0) uses armor to reduce damage
from 15 to 15. Remaining hp is 29
+++New Turn+++
[[Mage Turn]]Magician Action: Regen Mana -)Mana Regenerated 25.0 Health Re
generated 10.0Ashen-Shugar Ver(0) uses armor to reduce damage from 0 to 0.
Remaining hp is 48
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 17.0 hp o
f damage:][Sound::Wosh]Macros the Black Ver(0) uses armor to reduce damage
from 17 to 17. Remaining hp is 22
+++New Turn+++
[[Mage Turn]]Magician Action: Regen Health -)Health Changed From 22 HP to
62 HP
with Spell:Minor Healing for 0 hp of damage: Sound[:Warble]Ashen-Shugar Ve
r(0) uses armor to reduce damage from 0 to 0. Remaining hp is 48
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 18.0 hp of
damage:][Sound::Clink]Macros the Black Ver(0) uses armor to reduce damage
from 18 to 18. Remaining hp is 44
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:Fireball for 43.0 HP o
f damage:][Sound::Crackle Boom]Ashen-Shugar Ver(0) uses armor to reduce da
mage from 43 to 33. Remaining hp is 15
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 9.0 hp of
damage:][Sound::Wosh]Macros the Black Ver(0) uses armor to reduce damage f
rom 9 to 9. Remaining hp is 35
+++New Turn+++
[[Mage Turn]]Magician Action: Regen Mana -)Mana Regenerated 25.0 Health Re
generated 10.0Ashen-Shugar Ver(0) uses armor to reduce damage from 0 to 0.
Remaining hp is 15
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 50.0 hp o
f damage:][Sound::Wosh]Macros the Black Ver(0) uses armor to reduce damage
from 50 to 50. Remaining hp is 0
Warrior Ashen-Shugar Ver(0) Wins
[[Warrior [weapons=[Axe [soundItMakes()=:Clink, getName()=Weapon:Axe, getM
inimumImpact()=15.0, getMaximumImpact()=25.0], Sword [soundItMakes()=:Wosh
, getName()=Weapon:Sword, getMinimumImpact()=1.0, getMaximumImpact()=50.0]
, null, null, null], numberOfWeapons=2]]]
****************************************************
****** Round 2 ********
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:Fireball for 48.0 HP o
f damage:][Sound::Crackle Boom]Ashen-Shugar Ver(1) uses armor to reduce da
mage from 48 to 38. Remaining hp is 202
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 20.0 hp of
damage:][Sound::Clink]Macros the Black Ver(1) uses armor to reduce damage
from 20 to 20. Remaining hp is 100
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:IceStorm for 56.0 HP o
f damage:][Sound::Chatter Boom]Ashen-Shugar Ver(1) uses armor to reduce da
mage from 56 to 46. Remaining hp is 156
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 20.0 hp o
f damage:][Sound::Wosh]Macros the Black Ver(1) uses armor to reduce damage
from 20 to 20. Remaining hp is 80
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:Fireball for 44.0 HP o
f damage:][Sound::Crackle Boom]Ashen-Shugar Ver(1) uses armor to reduce da
mage from 44 to 34. Remaining hp is 122
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 18.0 hp of
damage:][Sound::Clink]Macros the Black Ver(1) uses armor to reduce damage
from 18 to 18. Remaining hp is 62
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:Fireball for 43.0 HP o
f damage:][Sound::Crackle Boom]Ashen-Shugar Ver(1) uses armor to reduce da
mage from 43 to 33. Remaining hp is 89
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 22.0 hp of
damage:][Sound::Clink]Macros the Black Ver(1) uses armor to reduce damage
from 22 to 22. Remaining hp is 40
+++New Turn+++
[[Mage Turn]][Magician Action: Attacks ->with Spell:Fireball for 43.0 HP o
f damage:][Sound::Crackle Boom]Ashen-Shugar Ver(1) uses armor to reduce da
mage from 43 to 33. Remaining hp is 56
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Axe for 18.0 hp of
damage:][Sound::Clink]Macros the Black Ver(1) uses armor to reduce damage
from 18 to 18. Remaining hp is 22
+++New Turn+++
[[Mage Turn]]Magician Action: Regen Health -)Health Changed From 22 HP to
62 HP
with Spell:Minor Healing for 0 hp of damage: Sound[:Warble]Ashen-Shugar Ve
r(1) uses armor to reduce damage from 0 to 0. Remaining hp is 56
[[Warrior Turn]][Warrior Action: Attacks ->with Weapon:Sword for 32.0 hp o
f damage:][Sound::Wosh]Macros the Black Ver(1) uses armor to reduce damage
from 32 to 32. Remaining hp is …
Purchase answer to see full
attachment
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more