Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- note
- description: "Finding routes in Zurich."
- class
- NAVIGATOR
- inherit
- ZURICH_OBJECTS
- feature -- Explore Zurich
- add_event_handlers
- -- Add handlers to mouse-click events on stations
- -- to allow the user to select start and end points of his route.
- do
- across
- Zurich.stations as i
- loop
- Zurich_map.station_view (i.item).on_left_click_no_args.extend_back (agent set_origin (i.item))
- Zurich_map.station_view (i.item).on_right_click_no_args.extend_back (agent set_destination (i.item))
- end
- Zurich_map.on_left_click_no_args.extend_back (agent show_route)
- Zurich_map.on_right_click_no_args.extend_back (agent show_route)
- end
- feature -- Write / Set
- set_origin (s: STATION)
- -- Set new origin
- require
- s_not_void: s /= void
- do
- origin := s
- ensure
- origin_exists: origin /= void
- origin = s
- end
- set_destination (s: STATION)
- -- Set new destination
- require
- s_exists: s /= void
- do
- destination := s
- ensure
- destination_exists: destination /= void
- destination = s
- end
- feature -- Access
- origin: STATION
- -- Currently selected start point.
- -- (Void if no start point selected).
- destination: STATION
- -- Currently selected end point.
- -- (Void if no end point selected).
- feature {NONE} -- Implementation
- show_route
- -- If both `origin' and `destination' are set, show the route from `origin' to `destination' on the map
- -- and output directions to the console.
- -- Otherwise do nothing.
- local
- find: ROUTE_FINDER
- shortest: ROUTE
- do
- if
- origin /= void and then destination /= void
- then
- zurich_map.update
- console.clear
- console.output ("From " + origin.name + " to " + destination.name + ":")
- create find.make (zurich)
- shortest := find.shortest_route (origin, destination)
- zurich.add_route (shortest)
- zurich_map.update
- shortest.minimize_lines
- console.append_line (shortest.out)
- zurich.remove_route (shortest)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement