diff --git a/lib/ruby_warrior/game.rb b/lib/ruby_warrior/game.rb index 59f00c47..dd97a963 100644 --- a/lib/ruby_warrior/game.rb +++ b/lib/ruby_warrior/game.rb @@ -1,8 +1,31 @@ +# String color methods taken from http://stackoverflow.com/a/16363159 + +class String + def black; "\033[30m#{self}\033[0m" end + def red; "\033[31m#{self}\033[0m" end + def green; "\033[32m#{self}\033[0m" end + def brown; "\033[33m#{self}\033[0m" end + def blue; "\033[34m#{self}\033[0m" end + def magenta; "\033[35m#{self}\033[0m" end + def cyan; "\033[36m#{self}\033[0m" end + def gray; "\033[37m#{self}\033[0m" end + def bg_black; "\033[40m#{self}\0330m" end + def bg_red; "\033[41m#{self}\033[0m" end + def bg_green; "\033[42m#{self}\033[0m" end + def bg_brown; "\033[43m#{self}\033[0m" end + def bg_blue; "\033[44m#{self}\033[0m" end + def bg_magenta; "\033[45m#{self}\033[0m" end + def bg_cyan; "\033[46m#{self}\033[0m" end + def bg_gray; "\033[47m#{self}\033[0m" end + def bold; "\033[1m#{self}\033[22m" end + def reverse_color; "\033[7m#{self}\033[27m" end +end + module RubyWarrior class Game def start - UI.puts "Welcome to Ruby Warrior" + UI.puts "Welcome to Ruby Warrior".bold.red if File.exist?(Config.path_prefix + '/.profile') @profile = Profile.load(Config.path_prefix + '/.profile') @@ -68,13 +91,13 @@ def play_normal_mode def play_current_level continue = true current_level.load_player - UI.puts "Starting Level #{current_level.number}" + UI.puts "Starting Level #{current_level.number}".bold current_level.play if current_level.passed? if next_level.exists? - UI.puts "Success! You have found the stairs." + UI.puts "\nSuccess!".green.bold + " You have found the stairs." else - UI.puts "CONGRATULATIONS! You have climbed to the top of the tower and rescued the fair maiden Ruby." + UI.puts "CONGRATULATIONS!".green.bold + " You have climbed to the top of the tower and rescued the fair maiden Ruby." continue = false end current_level.tally_points diff --git a/lib/ruby_warrior/level.rb b/lib/ruby_warrior/level.rb index c34d27fb..6841ef8f 100644 --- a/lib/ruby_warrior/level.rb +++ b/lib/ruby_warrior/level.rb @@ -49,7 +49,7 @@ def play(turns = 1000) load_level turns.times do |n| return if passed? || failed? - UI.puts "- turn #{n+1} -" + UI.puts "\n- " + "turn #{n+1}".bold.blue + " -" UI.print @floor.character @floor.units.each { |unit| unit.prepare_turn } @floor.units.each { |unit| unit.perform_turn } @@ -61,24 +61,25 @@ def play(turns = 1000) def tally_points score = 0 - UI.puts "Level Score: #{warrior.score}" + UI.puts "Level Score:".bold + " #{warrior.score}" score += warrior.score - UI.puts "Time Bonus: #{time_bonus}" + UI.puts "Time Bonus:".bold + " #{time_bonus}" score += @time_bonus if floor.other_units.empty? - UI.puts "Clear Bonus: #{clear_bonus}" + UI.puts "Clear Bonus:".bold + " #{clear_bonus}" score += clear_bonus end if @profile.epic? - UI.puts "Level Grade: #{grade_for(score)}" if grade_for(score) - UI.puts "Total Score: " + score_calculation(@profile.current_epic_score, score) + UI.puts "Level Grade:".bold + " #{grade_for(score)}" if grade_for(score) + UI.puts "Total Score: ".bold + score_calculation(@profile.current_epic_score, score) @profile.current_epic_grades[@number] = (score / ace_score.to_f) if ace_score @profile.current_epic_score += score else - UI.puts "Total Score: " + score_calculation(@profile.score, score) + UI.puts "Total Score: ".bold + score_calculation(@profile.score, score) \ + + "\n\n" @profile.score += score @profile.abilities = warrior.abilities.keys end diff --git a/lib/ruby_warrior/units/base.rb b/lib/ruby_warrior/units/base.rb index a7a2abd0..fb69c92d 100644 --- a/lib/ruby_warrior/units/base.rb +++ b/lib/ruby_warrior/units/base.rb @@ -23,10 +23,12 @@ def take_damage(amount) unbind if bound? if health self.health -= amount - say "takes #{amount} damage, #{health} health power left" + say "takes #{amount} damage, #{health} " + "health power".red \ + + " left" + if health <= 0 @position = nil - say "dies" + say "dies".bold.red end end end @@ -49,7 +51,15 @@ def bind end def say(msg) - UI.puts_with_delay "#{name} #{msg}" + # Might want to just switch the color based on whether it's a Warrior + # or a Golem or not, rather than print the entire string in both + # code bodies. (i.e., Have the print below the if / else block, + # and just change the color in the conditional switch.) + if self.class == Warrior or self.class == Golem + UI.puts_with_delay "#{name}".green.bold + " #{msg}" + else + UI.puts_with_delay "#{name}".brown.bold + " #{msg}" + end end def name