From 44c64ef7ea083ff39fdd7a1dfd77cdd8076fec9d Mon Sep 17 00:00:00 2001 From: smlance Date: Mon, 15 Jul 2013 10:37:09 -0400 Subject: [PATCH 1/3] Added newlines to output so that it's easier to read. --- lib/ruby_warrior/game.rb | 2 +- lib/ruby_warrior/level.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ruby_warrior/game.rb b/lib/ruby_warrior/game.rb index 59f00c47..1b613aec 100644 --- a/lib/ruby_warrior/game.rb +++ b/lib/ruby_warrior/game.rb @@ -72,7 +72,7 @@ def play_current_level current_level.play if current_level.passed? if next_level.exists? - UI.puts "Success! You have found the stairs." + UI.puts "\nSuccess! You have found the stairs." else UI.puts "CONGRATULATIONS! You have climbed to the top of the tower and rescued the fair maiden Ruby." continue = false diff --git a/lib/ruby_warrior/level.rb b/lib/ruby_warrior/level.rb index c34d27fb..df8008db 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} -" UI.print @floor.character @floor.units.each { |unit| unit.prepare_turn } @floor.units.each { |unit| unit.perform_turn } @@ -78,7 +78,8 @@ def tally_points @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: " + score_calculation(@profile.score, score) \ + + "\n\n" @profile.score += score @profile.abilities = warrior.abilities.keys end From 887ac66b4370bc02662254ed44a71fb13e41dcb8 Mon Sep 17 00:00:00 2001 From: smlance Date: Mon, 15 Jul 2013 11:13:34 -0400 Subject: [PATCH 2/3] Added basic colorized output. --- lib/ruby_warrior/game.rb | 31 +++++++++++++++++++++++++++---- lib/ruby_warrior/level.rb | 14 +++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/lib/ruby_warrior/game.rb b/lib/ruby_warrior/game.rb index 1b613aec..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 "\nSuccess! 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 df8008db..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 "\n- 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,24 @@ 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 From 6a165b58b45f68ef483a04de75596173bdd18136 Mon Sep 17 00:00:00 2001 From: smlance Date: Mon, 15 Jul 2013 12:09:01 -0400 Subject: [PATCH 3/3] Added more coloration. --- lib/ruby_warrior/units/base.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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