Created
December 31, 2015 12:42
-
-
Save bragboy/292449376f8cd1b6d9e5 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
#models/controller.rb | |
require 'observer' | |
class Controller | |
include Observable | |
attr_accessor :hotel | |
def initialize(num_floors, num_of_mc, num_of_sc) | |
@hotel = Hotel.new(num_floors, num_of_mc, num_of_sc, self) | |
end | |
def input | |
loop do | |
puts 'Enter any of the commands: MOTION, STATUS, EXIT, NOMOTION' | |
command = gets.chomp.downcase | |
if command.empty? || command == 'status' || command == 's' | |
puts hotel.current_status | |
elsif command == 'exit' || command == 'q!' || command == 'e' | |
puts 'Thank you!!' | |
break | |
elsif command == 'motion' || command == 'm' | |
print 'Enter floor number: ' | |
floor = gets.chomp.to_i | |
print 'Enter Sub Corridor number: ' | |
sub_corridor = gets.chomp.to_i | |
changed | |
notify_observers(floor, sub_corridor, true) | |
elsif command == 'nomotion' || command == 'n' | |
print 'Enter floor number: ' | |
floor = gets.chomp.to_i | |
print 'Enter Sub Corridor number: ' | |
sub_corridor = gets.chomp.to_i | |
changed | |
notify_observers(floor, sub_corridor, false) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment