-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.rb
40 lines (33 loc) · 916 Bytes
/
display.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true
require 'colorize'
require_relative 'cursor'
class Display
attr_reader :board, :cursor
def initialize(board)
@board = board
@cursor = Cursor.new([0, 0], @board)
@in_check = false
end
def render
print `clear`
@board.rows.each.with_index do |row, i|
row.each.with_index do |square, j|
background_color = (:yellow if [i, j] == @cursor.cursor_pos) || set_background([i, j])
if @cursor.selected && @cursor.cursor_pos == [i, j]
background_color = :green
end
print " #{square} ".colorize(color: square.color, background: background_color)
end
puts "\n"
end
puts 'You are currently in check.' if @in_check == true
end
def set_background(pos)
row, col = pos
return :light_black if row % 2 == col % 2
:light_blue
end
def in_check(boolean)
@in_check = boolean
end
end