Skip to content

Commit

Permalink
* Move moving logic from Robot to State.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledestin committed Sep 18, 2014
1 parent adfe68d commit b105203
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/robot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def left

def move
new_coords = @coords.clone
new_coords.x += direction.delta_x
new_coords.y += direction.delta_y
new_coords.step!
@coords = new_coords if @@table.contain?(new_coords.x, new_coords.y)
end

Expand Down
5 changes: 5 additions & 0 deletions lib/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ def initialize x, y, direction
raise ArgumentError, $!.message
end

def step!
self.x += direction.delta_x
self.y += direction.delta_y
end

def to_s
[x, y, direction].join ','
end
Expand Down

0 comments on commit b105203

Please sign in to comment.