Java Homework Each Character has Health Points and Skill Points, Items(to be equ
ID: 3839228 • Letter: J
Question
Java Homework
Each Character has Health Points and Skill Points, Items(to be equipped), Techniques(to be acquired or learned), Elemental Strengths and weaknesses(based on their type) and a Level based on Experience points XP. In a team where the party contains 2 or more of the same type of elemental character, each character of that given type earns a 10% bonus in attack power and health. If a party member has a greater elemental type, partners with a weaker elemental type earn 10% bonus in defense and skill points for each partner with a stronger element.
Elements:
Water[stronger] douses Fire[weaker]
Fire Scorches Earth
Earth withstands Thunder
Thunder pierces the Atmosphere(Wind)
Wind moves the Tide(Water)
Types:
Engineer, Android – Thunder
Soldier, Commander – Fire
Huntress, Assassin – Wind
Beastmaster, Swordsman – Earth
Healer, Mariner – Water
Specific Character types should inherit from the common base character. The level-up system should work as follows:
Level 1 health = 500 hp, xp needed for next level = (hp/20)^2.
Write methods that customize all other character details. In your javadoc comments, include the exact formula. Each character should have an additional field for battlefield advantage and Item equipment bonuses. Party member must also have a field for money earned that can later be spent on upgrades.
Explanation / Answer
class NeedlemanWunsch @min_score = nil def initialize(a, b, substitution_matrix, gap_penalty) @a = a @b = b # convert to array if a/b were strings @a = a.split("") if a.class == String @b = b.split("") if b.class == String @sm = substitution_matrix @gp = gap_penalty end def get_best_alignment construct_score_matrix return extract_best_alignment_from_score_matrix end def construct_score_matrix return if @score_matrix != nil #return if we've already calculated it initialize_score_matrix traverse_score_matrix do |i, j| if i==0 && j==0 @score_matrix[0][0] = 0 elsif i==0 #if this is a gap penalty square @score_matrix[0][j] = j * @gp elsif j==0 #if this is a gap penalty square @score_matrix[i][0] = i * @gp else up = @score_matrix[i-1][j] + @gp left = @score_matrix[i][j-1] + @gp #@a and @b are off by 1 because we added cells for gaps in the matrix diag = @score_matrix[i-1][j-1] + s(@a[i-1], @b[j-1]) max, how = diag, "D" max, how = up, "U" if up > max max, how = left, "L" if left > max @score_matrix[i][j] = max @score_matrix[i][j] = @min_score if @min_score != nil and max < @min_score @traceback_matrix[i][j] = how end end end def extract_best_alignment_from_score_matrix i = @score_matrix.length-1 j = @score_matrix[0].length-1 left = Array.new top = Array.new while i > 0 && j > 0 if @traceback_matrix[i][j] == "D" left.push(@a[i-1]) top.push(@b[j-1]) i -= 1 j -= 1 elsif @traceback_matrix[i][j] == "L" left.push "-" top.push @b[j-1] j -= 1 elsif @traceback_matrix[i][j] == "U" left.push @a[i-1] top.push "-" i -= 1 else puts "something strange happened" #this shouldn't happen end end return left.join.upcase.reverse, top.join.upcase.reverse end def print_score_visualization construct_score_matrix print_as_table(@score_matrix) end def print_traceback_matrix construct_score_matrix print_as_table(@traceback_matrix) end def print_as_table(the_matrix) puts puts "a=" + @a.to_s puts "b=" + @b.to_s puts print " " @b.each_index {|elem| print " " + @b[elem].to_s } puts "" traverse_score_matrix do |i, j| if j==0 and i > 0 print @a[i-1] elsif j==0 print " " end print " " + the_matrix[i][j].to_s puts "" if j==the_matrix[i].length-1 end end def traverse_score_matrix @score_matrix.each_index do |i| @score_matrix[i].each_index do |j| yield(i, j) end end end def initialize_score_matrix @score_matrix = Array.new(@a.length+1) @traceback_matrix = Array.new(@a.length+1) @score_matrix.each_index do |i| @score_matrix[i] = Array.new(@b.length+1) @traceback_matrix[i] = Array.new(@b.length+1) @traceback_matrix[0].each_index {|j| @traceback_matrix[0][j] = "L" if j!=0 } end @traceback_matrix.each_index {|k| @traceback_matrix[k][0] = "U" if k!=0 } @traceback_matrix[0][0] = "f" end def s(a, b) #check the score for bases a. b being aligned for i in 0..(@sm.length-1) break if a.downcase == @sm[i][0].downcase end for j in 0..(@sm.length-1) break if b.downcase == @sm[0][j].downcase end return @sm[i][j] end endRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.