Skip to content

Instantly share code, notes, and snippets.

@semmons99
Created February 23, 2011 19:06
Show Gist options
  • Select an option

  • Save semmons99/840958 to your computer and use it in GitHub Desktop.

Select an option

Save semmons99/840958 to your computer and use it in GitHub Desktop.
def move(params = {})
current_move = params[:current_move]
next_move = params[:next_move]
return up if current_move > @current_location
return down if current_move < @current_location
return open_door(next_move) if current_move == @current_location
idle
end
private
def idle
@status = :idle
end
def up
@status = :up
@direction = :up
@current_location += @speed
end
def down
@status = :down
@direction = :down
@current_location -= @speed
end
def open_door(next_move)
@status = :open
if next_move > @current_location
@direction = :up
elsif next_move < @current_location
@direction = :down
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment