Class: Termworld::Resources::Chip

Inherits:
Object
  • Object
show all
Defined in:
lib/termworld/resources/chip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y: nil, x: nil, key:) ⇒ Chip

Returns a new instance of Chip.



7
8
9
10
11
12
# File 'lib/termworld/resources/chip.rb', line 7

def initialize(y: nil, x: nil, key:)
  @y = y
  @x = x
  @key = key
  data
end

Instance Attribute Details

#movableObject (readonly)

Returns the value of attribute movable.



6
7
8
# File 'lib/termworld/resources/chip.rb', line 6

def movable
  @movable
end

Instance Method Details

#dataObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/termworld/resources/chip.rb', line 14

def data
  case @key
  when "00"
    @movable = true
    {
      background_color: {r: 300, g: 300, b: 300},
    }
  when "01"
    @movable = false
    {
      background_color: {r: 0, g: 0, b: 0},
    }
  when "pl"
    {
      background_color: {r: 200, b: 200, g: 800},
    }
  end
end

#rectObject



33
34
35
36
37
38
# File 'lib/termworld/resources/chip.rb', line 33

def rect
  TermCanvas::Rect.new(
    x: @x, y: @y, width: 2, height: 1,
    background_color: data[:background_color],
  )
end