Class: Cliptic::Main::Player::Cursor
- Inherits:
-
Object
- Object
- Cliptic::Main::Player::Cursor
- Defined in:
- lib/cliptic/main.rb
Instance Attribute Summary collapse
-
#grid ⇒ Object
readonly
Returns the value of attribute grid.
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
-
#initialize(grid:) ⇒ Cursor
constructor
A new instance of Cursor.
- #move(y:, x:) ⇒ Object
- #reset ⇒ Object
- #set(y:, x:) ⇒ Object
- #wrap ⇒ Object
Constructor Details
#initialize(grid:) ⇒ Cursor
Returns a new instance of Cursor.
580 581 582 |
# File 'lib/cliptic/main.rb', line 580 def initialize(grid:) @grid = grid end |
Instance Attribute Details
#grid ⇒ Object (readonly)
Returns the value of attribute grid.
579 580 581 |
# File 'lib/cliptic/main.rb', line 579 def grid @grid end |
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
579 580 581 |
# File 'lib/cliptic/main.rb', line 579 def pos @pos end |
Instance Method Details
#move(y:, x:) ⇒ Object
590 591 592 593 594 |
# File 'lib/cliptic/main.rb', line 590 def move(y:, x:) @pos[:y]+= y @pos[:x]+= x wrap end |
#reset ⇒ Object
586 587 588 589 |
# File 'lib/cliptic/main.rb', line 586 def reset grid.cell(**pos).focus Curses.curs_set(1) end |
#set(y:, x:) ⇒ Object
583 584 585 |
# File 'lib/cliptic/main.rb', line 583 def set(y:, x:) @pos = Pos.mk(y,x) end |
#wrap ⇒ Object
595 596 597 598 599 600 601 602 |
# File 'lib/cliptic/main.rb', line 595 def wrap pos[:x] += grid.sq[:x] while pos[:x] < 0 pos[:y] += grid.sq[:y] while pos[:y] < 0 pos[:x] -= grid.sq[:x] while pos[:x] >= grid.sq[:x] pos[:y] -= grid.sq[:y] while pos[:y] >= grid.sq[:y] end |