Class: Shape

Inherits:
Object
  • Object
show all
Includes:
UserInputs
Defined in:
lib/fantasy/shape.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UserInputs

#on_click, #on_click_do, #on_cursor_down, #on_cursor_down_do, #on_cursor_left, #on_cursor_left_do, #on_cursor_right, #on_cursor_right_do, #on_cursor_up, #on_cursor_up_do, #on_mouse_button_left, #on_mouse_button_left_do, #on_space_bar, #on_space_bar_do

Constructor Details

#initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil) ⇒ Shape

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fantasy/shape.rb', line 9

def initialize(kind:, position:, width:, height:, stroke: 1, fill: true, color: Color.palette.black, stroke_color: nil)
  @kind = kind
  @position = position
  @width = width
  @height = height
  @stroke = stroke
  @color = color
  @fill = fill
  @stroke_color = stroke_color
  @layer = 1

  Global.shapes << self
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def color
  @color
end

#fillObject

Returns the value of attribute fill.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def fill
  @fill
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def height
  @height
end

#kindObject

Returns the value of attribute kind.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def kind
  @kind
end

#layerObject

Returns the value of attribute layer.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def layer
  @layer
end

#positionObject

Returns the value of attribute position.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def position
  @position
end

#strokeObject

Returns the value of attribute stroke.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def stroke
  @stroke
end

#stroke_colorObject

Returns the value of attribute stroke_color.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def stroke_color
  @stroke_color
end

#widthObject

Returns the value of attribute width.



6
7
8
# File 'lib/fantasy/shape.rb', line 6

def width
  @width
end

Class Method Details

.rectangle(position:, width:, height:, color: Color.palette.black, stroke_color: nil, stroke: 0) ⇒ Object

rubocop:enable Metrics/ParameterLists



24
25
26
# File 'lib/fantasy/shape.rb', line 24

def self.rectangle(position:, width:, height:, color: Color.palette.black, stroke_color: nil, stroke: 0)
  Shape.new(kind: "rectangle", position: position, width: width, height: height, color: color)
end

Instance Method Details

#destroyObject



37
38
39
# File 'lib/fantasy/shape.rb', line 37

def destroy
  Global.shapes.delete(self)
end

#drawObject



28
29
30
31
32
33
34
35
# File 'lib/fantasy/shape.rb', line 28

def draw
  case @kind
  when "rectangle"
    draw_rectangle
  else
    raise "Shape.kind not supported: '#{@kind}'. Supported kinds: 'rectangle'"
  end
end