Created
December 5, 2013 04:16
-
-
Save ZacharyDinerstein/7799984 to your computer and use it in GitHub Desktop.
nyc subway threelines app
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
| @l_line = {:"8th Ave" => 1, :"6th" => 2, :"Union Square" => 3, :"3rd" => 4, :"1st" => 5} #DO I NEED TO MAKE THE SYMBOLS STRINGS? | |
| @n_line = {:"8th St" => 1,:"Union Square" => 2, :"23rd N" => 3, :"28th N" => 4, :"34th" => 5, :"Times Square" => 6} | |
| @six_line = {:"Astor Place" => 1, :"Union Square" => 2, :"23rd 6" => 3, :"28th 6" => 4, :"33rd" => 5, :"Grand Central" => 6} | |
| def location | |
| puts "Which stop are you at now?" | |
| @here = gets.chomp.to_sym | |
| train1 #Calls train1 | |
| end | |
| def train1 | |
| puts "...on which train? (l) (n) or (6)?" | |
| train = gets.chomp.to_s | |
| case train | |
| when "l" | |
| @train1 = @l_line | |
| when "n" | |
| @train1 = @n_line | |
| when "6" | |
| @train1 = @six_line | |
| end | |
| destination #Calls destination | |
| end | |
| def destination | |
| puts "Where do you want to go?" | |
| @there = gets.chomp.to_sym | |
| train2 #Calls train2 | |
| end | |
| def train2 | |
| puts "...on which train? (l) (n) or (6)?" | |
| train = gets.chomp.to_s | |
| case train | |
| when "l" | |
| @train2 = @l_line | |
| when "n" | |
| @train2 = @n_line | |
| when "6" | |
| @train2 = @six_line | |
| end | |
| distance #Calls distance | |
| end | |
| def distance | |
| path1 = (@train1[@here] - @train1[:"Union Square"]).abs #Figures out the number of stops | |
| path2 = (@train2[:"Union Square"] - @train2[@there]).abs #...we're traveling on each line and | |
| stops = path1 + path2 #...adds them together. | |
| puts "You have #{stops} stop(s) to go." | |
| end | |
| answer = location | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment