Class: Mastermind::Console::View

Inherits:
Object
  • Object
show all
Defined in:
lib/mastermind/console/view.rb

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.attempt_line(turn, width: 4) ⇒ Object



43
44
45
46
47
# File 'lib/mastermind/console/view.rb', line 43

def self.attempt_line(turn, width: 4)
  "#{turn.number}:".ljust(4) +
  SIDE + guess_bar(turn.guess.sequence) + BLANK * (width - turn.guess.length) + SIDE +
  feedback_line(exact: turn.exact, partial: turn.partial, width: width) + SIDE
end

.bottom_border(width: 4) ⇒ Object



39
40
41
# File 'lib/mastermind/console/view.rb', line 39

def self.bottom_border(width: 4)
  "    " + BL_CORNER + HORIZONTAL * width + BM_INTER + HORIZONTAL * width + BR_CORNER
end

.color_codesObject



29
30
31
32
33
# File 'lib/mastermind/console/view.rb', line 29

def self.color_codes
  Game::Piece::COLORS.map.with_index do |color, idx|
    "#{idx + 1}: #{piece_icon(color)}"
  end.join("  ") + "  q: exit"
end

.feedback_line(exact: 0, partial: 0, width: 4) ⇒ Object



49
50
51
# File 'lib/mastermind/console/view.rb', line 49

def self.feedback_line(exact: 0, partial: 0, width: 4)
  EXACT * exact + PARTIAL * partial + BLANK * (width - exact - partial)
end

.grading_schemeObject



25
26
27
# File 'lib/mastermind/console/view.rb', line 25

def self.grading_scheme
  "#{EXACT}: Matched color and position  #{PARTIAL}: Matched color"
end

.guess_bar(sequence) ⇒ Object



57
58
59
# File 'lib/mastermind/console/view.rb', line 57

def self.guess_bar(sequence)
  sequence.map { |piece| piece_icon(piece.color) }.join("")
end

.introductionObject



19
20
21
22
23
# File 'lib/mastermind/console/view.rb', line 19

def self.introduction
  "MASTERMIND\n" +
  "" +
  "\n"
end

.piece_icon(color) ⇒ Object



53
54
55
# File 'lib/mastermind/console/view.rb', line 53

def self.piece_icon(color)
  PIECE.colorize(color)
end

.top_border(width: 4) ⇒ Object



35
36
37
# File 'lib/mastermind/console/view.rb', line 35

def self.top_border(width: 4)
  "    " + TL_CORNER + HORIZONTAL * width + TM_INTER + HORIZONTAL * width + TR_CORNER
end