Class: Patience::EventHandler::Click

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Processable
Defined in:
lib/patience/event_handlers/click.rb

Overview

Click represents a state of every click in the game. Processable module endows Click with special abilities (the group of “detect” methods). Every object of Click has the scenario parameter, which is an instance of the Lambda. Thereby, an action, which should be performed on click, can be executed lately and lazily (on demand). Scenario is nothing but a bunch of certain actions, being performed on click.

cursor.click = EventHandler::Click.new(mouse_pos, areas)
cursor.click.card #=> Two of Hearts
cursor.click.card.pos  #=> (0, 0)
cursor.click.scenario.call # Perform some action on the card.
cursor.click.card.pos #=> (20, 20)

Instance Attribute Summary collapse

Attributes included from Processable

#area, #card, #pile

Instance Method Summary collapse

Methods included from Processable

#detect_in, #find_area_in, #find_card_in, #find_pile_in, #foundation?, #nothing?, #pick_up, #something?, #stock?, #tableau?, #to_a, #to_h, #waste?

Constructor Details

#initialize(mouse_pos, areas) ⇒ Click

Returns a new instance of Click.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/patience/event_handlers/click.rb', line 25

def initialize(mouse_pos, areas)
  @mouse_pos = mouse_pos
  @areas = areas
  @area = detect_area

  # If area has been detected, calculate other parameters too.
  if @area
    @pile = detect_pile
    @cards = collect_cards # A clicked card and tail cards.
    @card = cards.keys.first if @cards # The very clicked card.
    # Offset for dragged card.
    @offset = pick_up(@card, mouse_pos) if @card and something?

    @scenario = -> { stock }
  end
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



23
24
25
# File 'lib/patience/event_handlers/click.rb', line 23

def cards
  @cards
end

#offsetObject (readonly)

Returns the value of attribute offset.



23
24
25
# File 'lib/patience/event_handlers/click.rb', line 23

def offset
  @offset
end

#scenarioObject (readonly)

Returns the value of attribute scenario.



23
24
25
# File 'lib/patience/event_handlers/click.rb', line 23

def scenario
  @scenario
end