Class: ColorTheCircles::Presenter::Board
- Inherits:
-
Object
- Object
- ColorTheCircles::Presenter::Board
- Defined in:
- app/color_the_circles/presenter/board.rb
Constant Summary collapse
- WINDOW_WIDTH =
800- WINDOW_HEIGHT =
600- COLOR_RANGE =
(0..200)
- SHAPE_MIN_SIZE =
15- SHAPE_MAX_SIZE =
75- MARGIN_WIDTH =
55- MARGIN_HEIGHT =
155
Instance Attribute Summary collapse
-
#circles_data ⇒ Object
readonly
Returns the value of attribute circles_data.
-
#game ⇒ Object
readonly
Returns the value of attribute game.
Instance Method Summary collapse
- #add_circle ⇒ Object
- #fill_circle(circle_data) ⇒ Object
- #find_circle(x, y) ⇒ Object
-
#initialize(game) ⇒ Board
constructor
A new instance of Board.
- #restart_game ⇒ Object
Constructor Details
#initialize(game) ⇒ Board
Returns a new instance of Board.
14 15 16 17 |
# File 'app/color_the_circles/presenter/board.rb', line 14 def initialize(game) @game = game @circles_data = [] end |
Instance Attribute Details
#circles_data ⇒ Object (readonly)
Returns the value of attribute circles_data.
12 13 14 |
# File 'app/color_the_circles/presenter/board.rb', line 12 def circles_data @circles_data end |
#game ⇒ Object (readonly)
Returns the value of attribute game.
12 13 14 |
# File 'app/color_the_circles/presenter/board.rb', line 12 def game @game end |
Instance Method Details
#add_circle ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/color_the_circles/presenter/board.rb', line 24 def add_circle circle_x = rand * (WINDOW_WIDTH - MARGIN_WIDTH - SHAPE_MAX_SIZE) + SHAPE_MAX_SIZE circle_y = rand * (WINDOW_HEIGHT - MARGIN_HEIGHT - SHAPE_MAX_SIZE) + SHAPE_MAX_SIZE circle_size = rand * (SHAPE_MAX_SIZE - SHAPE_MIN_SIZE) + SHAPE_MIN_SIZE stroke_color = [rand(COLOR_RANGE), rand(COLOR_RANGE), rand(COLOR_RANGE)] circles_data << { args: [circle_x, circle_y, circle_size], fill: nil, stroke: stroke_color } game.score -= 1 # notifies score observers automatically of change end |
#fill_circle(circle_data) ⇒ Object
41 42 43 44 45 |
# File 'app/color_the_circles/presenter/board.rb', line 41 def fill_circle(circle_data) circle_data[:fill] = circle_data[:stroke] push_colored_circle_behind_uncolored_circles(circle_data) game.score += 1 # notifies score observers automatically of change end |
#find_circle(x, y) ⇒ Object
37 38 39 |
# File 'app/color_the_circles/presenter/board.rb', line 37 def find_circle(x, y) circles_data.find { |circle_data| circle_data[:fill].nil? && circle_data[:circle]&.contain?(x, y) } end |
#restart_game ⇒ Object
19 20 21 22 |
# File 'app/color_the_circles/presenter/board.rb', line 19 def restart_game game.restart_game circles_data.clear end |