Sha256: 6cd07a5db8033d5dd959da7323ec146cf9b635793b3633574809dbc2173a0a34
Contents?: true
Size: 1.64 KB
Versions: 1
Compression:
Stored size: 1.64 KB
Contents
require "colorize" module Mastermind module Console class View TL_CORNER = "\u250F" TM_INTER = "\u2533" TR_CORNER = "\u2513" BL_CORNER = "\u2517" BM_INTER = "\u253B" BR_CORNER = "\u251B" HORIZONTAL = "\u2501" SIDE = "\u2503" BLANK = " " PIECE = "\u25CF" EXACT = "\u25CF".red PARTIAL = "\u25CF".white def self.introduction "MASTERMIND\n" + "" + "\n" end def self.grading_scheme "#{EXACT}: Matched color and position #{PARTIAL}: Matched color" end def self.color_codes Game::Piece::COLORS.map.with_index do |color, idx| "#{idx + 1}: #{piece_icon(color)}" end.join(" ") + " q: exit" end def self.top_border(width: 4) " " + TL_CORNER + HORIZONTAL * width + TM_INTER + HORIZONTAL * width + TR_CORNER end def self.bottom_border(width: 4) " " + BL_CORNER + HORIZONTAL * width + BM_INTER + HORIZONTAL * width + BR_CORNER end def self.attempt_line(turn, width: 4) "#{turn.number}:".ljust(4) + SIDE + guess_bar(turn.guess.sequence) + BLANK * (width - turn.guess.sequence.length) + SIDE + feedback_line(exact: turn.exact, partial: turn.partial, width: width) + SIDE end def self.feedback_line(exact: 0, partial: 0, width: 4) EXACT * exact + PARTIAL * partial + BLANK * (width - exact - partial) end def self.piece_icon(color) PIECE.colorize(color) end def self.guess_bar(sequence) sequence.map { |piece| piece_icon(piece.color) }.join("") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mastermind-game-0.0.1 | lib/mastermind/console/view.rb |