Class: Patience::Cursor
- Extended by:
- Forwardable
- Defined in:
- lib/patience/cursor.rb
Overview
Patience::Cursor is a high-level class, which deals with all events in the game. Cursor always knows current position of the mouse.
cursor = Cursor.new
always { @cursor.mouse_pos = mouse_pos }
cursor.clicked_something? #=> false
cursor.still_on_something? #=> false
Instance Attribute Summary collapse
-
#click ⇒ Object
Returns the value of attribute click.
-
#drag ⇒ Object
Returns the value of attribute drag.
-
#drop ⇒ Object
Returns the value of attribute drop.
-
#mouse_pos ⇒ Object
Returns the value of attribute mouse_pos.
Instance Method Summary collapse
-
#carrying_card? ⇒ Boolean
Returns true if cursor clicked something different from nothing.
- #click! ⇒ Object
-
#clicked_something? ⇒ Boolean
Checks whether cursor clicked something.
-
#drop! ⇒ Object
Calls calculated scenario for the drop event and then refreshes click, drag and drop by setting them to nil.
-
#movable? ⇒ Boolean
(also: #drawable?)
Returns true if cursor clicked some card and that card is avaliable for dragging (e.g. its face is up).
-
#still_on_something? ⇒ Boolean
Checks whether cursor is still over the clicked object by asking card or pile, if the mouse_pos is within the pale of them.
Instance Attribute Details
#click ⇒ Object
Returns the value of attribute click.
13 14 15 |
# File 'lib/patience/cursor.rb', line 13 def click @click end |
#drag ⇒ Object
Returns the value of attribute drag.
13 14 15 |
# File 'lib/patience/cursor.rb', line 13 def drag @drag end |
#drop ⇒ Object
Returns the value of attribute drop.
13 14 15 |
# File 'lib/patience/cursor.rb', line 13 def drop @drop end |
#mouse_pos ⇒ Object
Returns the value of attribute mouse_pos.
13 14 15 |
# File 'lib/patience/cursor.rb', line 13 def mouse_pos @mouse_pos end |
Instance Method Details
#carrying_card? ⇒ Boolean
Returns true if cursor clicked something different from nothing. And by “something different” I mean any card.
54 55 56 |
# File 'lib/patience/cursor.rb', line 54 def click and card end |
#click! ⇒ Object
15 16 17 |
# File 'lib/patience/cursor.rb', line 15 def click! @click.scenario.call end |
#clicked_something? ⇒ Boolean
Checks whether cursor clicked something. If so, also checks, if the cursor is still in boundaries of that object at the time of mouse button release. Returns true, if this is true. Otherwise, returns false.
29 30 31 |
# File 'lib/patience/cursor.rb', line 29 def clicked_something? click and click.something? and still_on_something? end |
#drop! ⇒ Object
Calls calculated scenario for the drop event and then refreshes click, drag and drop by setting them to nil.
21 22 23 24 |
# File 'lib/patience/cursor.rb', line 21 def drop! @drop.scenario.call @click, @drag, @drop = nil, nil, nil end |
#movable? ⇒ Boolean Also known as: drawable?
Returns true if cursor clicked some card and that card is avaliable for dragging (e.g. its face is up). Otherwise, returns false.
48 49 50 |
# File 'lib/patience/cursor.rb', line 48 def movable? and draggable? end |
#still_on_something? ⇒ Boolean
Checks whether cursor is still over the clicked object by asking card or pile, if the mouse_pos is within the pale of them. Returns true, if this is true. Otherwise, returns false.
36 37 38 39 40 41 42 43 44 |
# File 'lib/patience/cursor.rb', line 36 def still_on_something? if card.hit?(mouse_pos) elsif pile pile.hit?(mouse_pos) else false end end |