-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.rb
46 lines (38 loc) · 869 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
41
42
43
44
45
46
require "colorize"
require_relative "cursor"
require_relative "board"
class Display
attr_reader :cursor
def initialize (board)
@board = board
@cursor = Cursor.new([0,0], board)
end
def render
system("clear")
print "\n"
# (0..7).each { |col| print " #{col}" }
(0..7).each do |row|
print "\n|"
(0..7).each do |col|
render_pos(row, col)
end
end
print "\nCHECK" if @board.in_check?(:w) || @board.in_check?(:b)
print "\n"
end
private
def render_pos(row, col)
piece = @board[[row, col]]
symbol = piece.to_s
print " "
if [row, col] == @cursor.cursor_pos
if @cursor.selected
print "#{symbol} ".colorize(:background => :red)
else
print "#{symbol} ".colorize(:background => :blue)
end
else
print "#{symbol} "
end
end
end