class Pointer

This class is responsible for keeping track of it’s location on the code map and moving in a direction every iteration.

Constants

DIRECTIONS
DIRECTIONS_MAP

Attributes

direction[RW]
trampoline[RW]
x[RW]
y[RW]

Public Class Methods

new(direction = :e) click to toggle source
# File lib/pointer.rb, line 11
def initialize(direction = :e)
  @direction = direction
  @x, @y = 0, 0
  @trampoline = false
end

Public Instance Methods

step() click to toggle source
# File lib/pointer.rb, line 17
def step
  diff = DIRECTIONS_MAP[@direction]
  multiplier = @trampoline ? 2 : 1
  self.x = x + diff.first * multiplier
  self.y = y + diff.last * multiplier
  self.x = x % 80
  self.y = y % 20
  @trampoline = false
end