Class: Patience::EventHandler::Click
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
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#scenario ⇒ Object
readonly
Returns the value of attribute scenario.
Attributes included from Processable
Instance Method Summary collapse
-
#initialize(mouse_pos, areas) ⇒ Click
constructor
A new instance of Click.
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
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
23 24 25 |
# File 'lib/patience/event_handlers/click.rb', line 23 def cards @cards end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
23 24 25 |
# File 'lib/patience/event_handlers/click.rb', line 23 def offset @offset end |
#scenario ⇒ Object (readonly)
Returns the value of attribute scenario.
23 24 25 |
# File 'lib/patience/event_handlers/click.rb', line 23 def scenario @scenario end |