forked from lorint/refactored_tfl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfl.rb
39 lines (28 loc) · 1.1 KB
/
tfl.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'pry'
require './station'
require './seeds' # Load up @lines and @stations
require './move'
# We start with Oxford Circus
my_station = @stations.select {|station| station.name.start_with? "Oxford"}.first
# Let people move around the stations, one hop at a time
prev_line = nil
loop do
puts "#{"After riding on " + prev_line.name + " " if !prev_line.nil?} You're at #{my_station.name}"
puts "Pick one! (or Q to exit)"
my_station.neighbors.each_with_index do |station, idx|
# %%%TODO (Lorin) For some reason, stations come in as nil when we're near the end of a line.
next if station.nil?
puts "#{idx + 1}. #{station.name}"
end
choice = gets.chomp
# Bail if they're tired of going around the tube
break if choice == "" || choice.downcase == "q"
choice = choice.to_i
# Hold on to all the neighbors for the previous station
nbrs = my_station.neighbors
# Hold on to a list of all the previous lines from the previous station
prev_all_lines = my_station.lines
# Go to the new station
my_station = nbrs[choice - 1]
prev_line = (prev_all_lines & my_station.lines).first
end