Class: Cliptic::Main::Player::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/cliptic/main.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#gridObject (readonly)

Returns the value of attribute grid.


579
580
581
# File 'lib/cliptic/main.rb', line 579

def grid
  @grid
end

#posObject (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

#resetObject


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

#wrapObject


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