From: Ira W. Snyder Date: Sun, 7 Oct 2007 04:07:31 +0000 (-0700) Subject: Get ready to add the calls into the GUI into Elevator X-Git-Url: https://irasnyder.com/gitweb/?a=commitdiff_plain;ds=inline;h=0f2350d5ad9a6bc431bbcce84e8b61a784328bea;p=cs356-p1-elevator.git Get ready to add the calls into the GUI into Elevator Clean up so that I can add the calls into the GUI in the Elevator class. Signed-off-by: Ira W. Snyder --- diff --git a/main.cpp b/main.cpp index bcfe3b3..9b2d2e0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,77 +1,64 @@ -#include -#include -#include -using namespace std; - -#include "stop.hpp" -#include "position.hpp" -#include "elevator.hpp" -#include "elevatorcontroller.hpp" -#include "elevatorgui.hpp" - -#include +#include "main.hpp" +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); - - -#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); - - Stop s4(4, DOWN); - e.stop_at (s4); - - Stop s5(5, ALL); - e.stop_at (s5); - - for (int i=0; i<100; ++i) - { - usleep (500000); - e.move (); - } -#endif - return 0; }