Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making output easier to read #69

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions lib/ruby_warrior/game.rb
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions lib/ruby_warrior/level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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
Expand Down
16 changes: 13 additions & 3 deletions lib/ruby_warrior/units/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down