Created
February 23, 2011 19:06
-
-
Save semmons99/840958 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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