main
 1class Location
 2  def initialize(x, y, heading)
 3    @location = {:x => x, :y => y}
 4    @heading = heading
 5  end
 6
 7  def forward(plateau)
 8    @heading.forward(self, plateau)
 9  end
10
11  def rotate(degrees)
12    @heading = @heading.rotate(degrees)
13  end
14
15  def is_facing(direction)
16    @heading.represents? direction
17  end
18
19  def current(axis)
20    return @location[axis]
21  end
22
23  def move_to(axis, coordinate)
24    @location[axis] = coordinate
25  end
26
27  def increment(axis, map)
28    next_position = current(axis) + 1
29    move_to(axis, (next_position > map[axis]) ? 0 : next_position )
30  end
31
32  def decrement(axis, map)
33    next_position = current(axis) - 1
34    move_to(axis, (next_position < 0) ? map[axis] : next_position)
35  end
36
37  def to_s
38    "#{@location[:x]} #{@location[:y]} #{@heading}"
39  end
40end