class Model::Compass

Constants

DIRECTIONS

Attributes

direction[R]

Public Class Methods

new(direction) click to toggle source
# File lib/karel/model/compass.rb, line 14
def initialize(direction)
  @direction = direction
end

Public Instance Methods

translate_location(location) click to toggle source
# File lib/karel/model/compass.rb, line 18
def translate_location(location)
  Location.new(
    location.x + DIRECTIONS[direction][0],
    location.y + DIRECTIONS[direction][1]
  )
end
turn() click to toggle source
# File lib/karel/model/compass.rb, line 25
def turn
  dir_index = DIRECTIONS.keys.index(direction)
  dir_index += 1
  dir_index %= DIRECTIONS.length
  self.class.new(DIRECTIONS.keys[dir_index])
end