X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=main.cpp;h=5ac3fe9c8f84bbc4025f13e5e983bb8b616e1212;hb=2172ce055533d5865d58538ee00bf609e59b0f99;hp=bcfe3b352acda7a783a70818f1bbaea1568466cb;hpb=a3b0112117bfb69d7d2053e0f4f5b1220b95379b;p=cs356-p1-elevator.git diff --git a/main.cpp b/main.cpp index bcfe3b3..5ac3fe9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,78 +1,92 @@ -#include -#include -#include -using namespace std; - -#include "stop.hpp" -#include "position.hpp" -#include "elevator.hpp" -#include "elevatorcontroller.hpp" +#include "main.hpp" #include "elevatorgui.hpp" -#include - +static ElevatorGUI *thegui = NULL; int main (int argc, char *argv[]) { - const int floors = 7; - const int elevators = 3; + int floors = 7; + int elevators = 3; + +//#define USE_STATIC_FLOORS 1 +#ifndef USE_STATIC_FLOORS + do + { + std::cout << "Enter the number of floors to use [2-10]: "; + std::cin >> floors; + + if (floors < 2 || floors > 10) + { + std::cout << "You entered: " << floors + << " which is outside the acceptable range." << std::endl; + std::cout << "Please try again..." << std::endl << std::endl; + } + else + { + // Good input, leave now + break; + } + } while (true); + + do + { + std::cout << "Enter the number of elevators to use [1-5]: "; + std::cin >> elevators; + + if (elevators < 1 || elevators > 5) + { + std::cout << "You entered: " << elevators + << " which is outside the acceptable range." << std::endl; + std::cout << "Please try again..." << std::endl << std::endl; + } + else + { + // Good input, leave now + break; + } + } while (true); +#endif // Start GTK Gtk::Main app(argc, argv); + // Start the GUI ElevatorGUI eg(floors, elevators); + thegui = ⪚ + + // Show the GUI eg.show (); + // Run it! Gtk::Main::run (eg); + return 0; +} -#if TEST_ELEVATORCONTROLLER - const int floors = 10; - const int elevators = 2; - - ElevatorController ec(floors, elevators); - - //ec.elevator_request (0, 2); - ec.call_elevator_to (3, DOWN); - - for (int i=0; i<35; i++) - ec.move_elevators (); - - // Note: without the GUI, this is dependent on choosing the same elevator - // that was randomly chosen by the call_elevator_to() funtion. - // - // This may need to be run a few times to work :) - ec.elevator_request (0, 2); - - for (int i=0; i<35; i++) - ec.move_elevators (); -#endif - - -#if TEST_ELEVATOR - Elevator e(2); - - Stop s2(3, DOWN); - e.stop_at (s2); - - Stop s3(1, UP); - e.stop_at (s3); +void gui_update_position_label (int elevator, float new_position, Direction direction) +{ + thegui->gui_update_position_label (elevator, new_position, direction); +} - Stop s4(4, DOWN); - e.stop_at (s4); +void gui_unpress_call_button (int floor, Direction direction) +{ + thegui->gui_unpress_call_button (floor, direction); +} - Stop s5(5, ALL); - e.stop_at (s5); +void gui_unpress_request_button (int elevator, int floor) +{ + thegui->gui_unpress_request_button (elevator, floor); +} - for (int i=0; i<100; ++i) - { - usleep (500000); - e.move (); - } -#endif +void gui_open_door (int elevator, int floor) +{ + thegui->gui_open_door (elevator, floor); +} - return 0; +void gui_close_door (int elevator, int floor) +{ + thegui->gui_close_door (elevator, floor); } /* vim: set ts=4 sts=4 sw=4 noet tw=112: */