class Mastermind::Oscar::Printer
Public Class Methods
colors()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 19 def self.colors { "R" => :red, "G" => :green, "B" => :blue, "Y" => :yellow, "C" => :cyan, "M" => :magenta } end
colour_background(content, colour)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 41 def self.colour_background (content, colour) content.colorize(:background => colour) end
colour_background_text(content, colour, b_colour)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 45 def self.colour_background_text (content, colour, b_colour) content.colorize(:background => b_colour).colorize(:color => colour) end
colour_letters(word)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 30 def self.colour_letters(word) word = word.split("") unless word.is_a?(Array) word = word.map!{ |letter| colour_text(letter,colors[letter]) } word.join end
colour_text(content, colour)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 37 def self.colour_text (content, colour) content.colorize(:color => colour) end
congratulations(user,color,guess, time)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 172 def self.congratulations(user,color,guess, time) output <<-EOS \tCongratulations!!! #{user} You guessed the sequence #{color} in #{guess} guesses over #{time}\n EOS end
format_input_query()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 53 def self.format_input_query output game_message end
game_message()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 90 def self.game_message mess = <<-EOS \t* Enter p to play \t* Enter i for instructions \t* Enter t for top scores \t* Enter r for records \t* Enter q to quit \n EOS end
game_over(user, color)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 162 def self.game_over(user, color) output <<-EOS \t ____ ______ ______ _______ __________ \t (( __||=||| \/ ||== (( ))\ //|==||_// \t \\_||| ||| ||___ \\_// \V/||__|| \\ \t\tYou have used up all your guesses. EOS show_cheat(color) end
greet_user(user, a, diff, csize, colors)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 137 def self.greet_user(user, a, diff, csize, colors) output <<-EOS \n\t\t.:: Nice to meet you, #{user} ::. Ok, I have generated a #{diff} sequence with #{csize} elements made of : \t#{colors} \tEnter (q)uit at any time to exit the game\n\n \t CAN YOU GUESS THE SEQUENCE? EOS end
initialize()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 7 def self.initialize set_output_stream end
level_select_msg()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 116 def self.level_select_msg output <<-EOS ******* SET GAME DIFFICULTY ******* * Enter b for beginner * Enter i for intermediate * Enter a for expert [invalid entry will default to beginner] \n EOS end
line()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 158 def self.line puts "-"*80 + "\n\n" end
output(content)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 11 def self.output (content) @@stream.puts content end
output_file(file)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 57 def self.output_file(file) file.each do |f| f.each_line do |line| fColor = line.split("\t\t") if fColor.size == 2 fColor[-1] = colour_letters(fColor.last); line = fColor.join("\t\t") end print line end f.close puts "\n\n" end end
output_top_ten(level, array,time_obj)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 72 def self.output_top_ten(level, array,time_obj) puts "\t\t*****#{level.upcase} Leaderboard*****" count = 1 array.each do |entry| name = entry[:name] code = colour_letters(entry[:code]) guess = entry[:guess] time = time_obj.get_time(entry[:time]) output(top_score_display_text(count,name,code,guess,time)) count += 1 end puts "" end
quit_msg(user)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 127 def self.quit_msg(user) output <<-EOS \n\t\t.:::::::::. Thank you for playing, #{user} .::::::::::. \t \t\t+-+-+-+-+-+-+-+ \t\t|C|I|A|O|!|!|!| \t\t+-+-+-+-+-+-+-+ EOS end
set_output_stream(stream = STDOUT)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 49 def self.set_output_stream (stream = STDOUT) @@stream = stream end
show_cheat(code)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 148 def self.show_cheat(code) output <<-EOS \n\t\t\tThe sequence is \t\t\t ======== \t\t\t ||#{code}|| \t\t\t ========\n\n EOS line end
stream()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 15 def self.stream @@stream end
top_score_display_text(count,name,code,guess,time)
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 86 def self.top_score_display_text(count,name,code,guess,time) "#{count}. #{name} solved '#{code}' in #{guess} guesses over #{time}" end
welcome_msg()
click to toggle source
# File lib/mastermind/oscar/printer.rb, line 101 def self.welcome_msg output <<-EOS ( ` ) ( )\))( ) ( /( ( ( ) ( )\ ) ((_)()\ ( /( ( )\()) ))\ )( ( )\ ( (()/( (_()((_) )(_)) )\ (_))/ /((_)(()\ )\ '((_) )\ ) ((_)) | \/ |((_)_ ((_)| |_ (_)) ((_) _((_)) (_) _(_/( _| | | |\/| |/ _` |(_-<| _|/ -_) | '_|| ' \() | || ' \))/ _` | |_| |_|\__,_|/__/ \__|\___| |_| |_|_|_| |_||_||_| \__,_| " \n\t\t.::::::::::::::. WELCOME .:::::::::::::::.\n\n EOS end