-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.rb
49 lines (36 loc) · 1.14 KB
/
cell.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
47
48
49
class Cell
CELL_WIDTH = 5
attr_accessor :index, :x, :y, :content, :piece
def initialize(options = {})
self.index = options[:index]
self.content = options[:content]
self.piece = options[:piece]
self.x = options[:x]
self.y = options[:y]
end
def empty?
self.content.nil? || self.content == " "
end
def inspect
{
content: content,
piece: piece,
x: x,
y: y
}
end
def render
case content
when " ", nil # Empty board space
content.center(CELL_WIDTH).colorize(color: :blue, background: :blue)
when "B" # Building
content.center(CELL_WIDTH).colorize(mode: :bold, color: :light_yellow, background: :light_black)
when "C" # Red car
content.center(CELL_WIDTH).colorize(mode: :bold, color: :light_red, background: :red)
when "R" # Road (part of a police block, which can be considered unblocked)
content.center(CELL_WIDTH).colorize(mode: :bold, color: :white, background: :white)
when "P" # Police car
content.center(CELL_WIDTH).colorize(mode: :bold, color: :blue, background: :light_white)
end
end
end