Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In video games, especially those in the roleplaying genre, it is common that characters in the game are advanced in power through the use of
In video games, especially those in the roleplaying genre, it is common that characters in the game are
advanced in power through the use of a skill tree. Generally, a skill tree defines the prerequisite for the
various skills that your character in the game might acquire. For example, in a hypothetical game, if
the Shield Bash, Defensive Stance, and Shield Ally skills all require that your character first have the skill
Shield Proficiency, then this might be represented by the following skill tree:
More formally, a skill in the skill tree can only be gained if the character first gains all of the skills
which are ancestors of that skill in the tree
Your Tasks
Your task in this question is to write a class called SkillTree which extends BasicMAryTree
an mary tree of Skill objects; a complete Skill.java is provided A template for the SkillTree
class is provided. It contains a constructor and a couple of useful methods. You will add additional
methods to this class in the following steps, which you should complete in order:
a Write a main method in the SkillTree class in which you construct your own skill tree for your
own hypothetical video game. Your tree must contain at least skills. However, for the sanity
of everyone involved, try to keep it under skills. Be creative! There is no reason why any
two students should hand in exactly the same or even very similar skill trees, nor should you
just duplicate the skill tree shown in the sample output. Print your tree to the console using the
toStringByLevel method inherited from BasicMAryTree
b Write a method in the SkillTree class called skillDependencies which takes a skill name as
input and returns an instance of LinkedList which contains all the of the skills which
are prerequisites for obtaining the input skill including the input skill itself! A RuntimeException
exception should be thrown if the tree does not contain the given skill. A good implementation
approach for this method is to use a recursive traversal of the tree to find the named skill, and
then add skills to the output list as the recursion unwinds. Tutorial includes some discussion of
recursive traversal of mary trees. Add to your main program a few tests of this method, and
print out the lists that is returned you can use the lists toString method for this Be sure to
test the case where the named skill does not exist in the tree.
c Write a method in the SkillTree class called skillTotalCost which takes a skill name as in
put and returns the total number of skill points that a player must invest to obtain the given
skill. If the named skill is not in the skill tree, then the skillTotalCost method should throw
a RuntimeException exception. Hint: this method is quite easy to implement if you make use of the
previously implemented skillDependencies method.
For example, in the above skill tree, if a character wants the Shield Ally skill they would need to
spend skill point to get Shield Proficiency, and then spend skill points to get Shield Ally for an In the video game world, the term skill tree sometimes refers to things that actually arent trees; a noteworthy example is the skill tree in the ARPG Path Of Exile, which, if you click the link, can see is clearly not a tree, even though they call it that. Here in question we used the term skill trees to mean skill trees that are, in fact, actual trees. overall investment of points, so for the above tree, skillTotalCostShield Ally"
should return Note that the Skill object contains the cost of the skill.
Add to your main program a few tests of skillTotalCost, and print out the total costs returned.
Be sure to test the case where the named skill does not exist in the tree.
d Run your main program. Cut and paste the console output to a text file and submit it with your
assignment.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started