class Upwords::Cursor

Attributes

x[R]
y[R]

Public Class Methods

new(max_y, max_x, init_y = 0, init_x = 0) click to toggle source
# File lib/upwords/cursor.rb, line 5
def initialize(max_y, max_x, init_y = 0, init_x = 0)
  @max_y = max_y
  @max_x = max_x

  # HACK: Force init_y, init_x to be in bounds
  @y = init_y % @max_y
  @x = init_x % @max_x 
end

Public Instance Methods

down() click to toggle source
# File lib/upwords/cursor.rb, line 18
def down
  move(1, 0)
end
left() click to toggle source
# File lib/upwords/cursor.rb, line 22
def left
  move(0, -1)
end
move(dy, dx) click to toggle source
# File lib/upwords/cursor.rb, line 30
def move(dy, dx)
  @y = (y + dy) % @max_y
  @x = (x + dx) % @max_x 
end
pos() click to toggle source
# File lib/upwords/cursor.rb, line 35
def pos
  [y, x]
end
right() click to toggle source
# File lib/upwords/cursor.rb, line 26
def right
  move(0, 1)
end
up() click to toggle source
# File lib/upwords/cursor.rb, line 14
def up
  move(-1, 0)
end