예제 #1
0
        //Call elevator
        public static String[][] CallElevator(List <Lift> allLifts, String[][] buildingStructure, int totalFloors, int totalLifts)
        {
            bool logicalInput       = false;
            int  personCurrentFloor = 0;
            int  personCalledFloor  = 0;

            //Prevent pushing the same floor button
            while (!logicalInput)
            {
                personCurrentFloor = UserInput.CurrentFloorInput(totalFloors);
                personCalledFloor  = UserInput.DesiredFloorInput(totalFloors);

                if (personCurrentFloor == personCalledFloor)
                {
                    Console.WriteLine();
                    Console.WriteLine("That makes no sense..");
                    Console.WriteLine();
                }
                else
                {
                    logicalInput = true;
                }
            }

            Console.Clear();

            //Select best lift for action
            LiftMethods.CalculateDistancesToCalledFloor(allLifts, personCurrentFloor, personCalledFloor, totalFloors);
            int closestLift = LiftMethods.ChooseLift(allLifts);

            //Temp store direction to override natural movement.
            int tempDirectionOverride = Utilities.GetTempDirectionOverride(allLifts, closestLift);

            LiftMethods.NaturalLiftMovement(allLifts, buildingStructure, totalFloors);
            LiftMethods.NaturalPeopleMovement(allLifts);

            //Set floor and direction from user action and adjust markers
            buildingStructure[allLifts[closestLift].CurrentFloor][allLifts[closestLift].ID] = "[ ] ";
            Utilities.SetNewDirection(allLifts[closestLift], tempDirectionOverride);
            Utilities.SetNewFloor(allLifts[closestLift], personCalledFloor);
            buildingStructure = LiftMethods.LinkLifts(allLifts, buildingStructure, totalFloors, totalLifts);
            Building.Display(buildingStructure, totalFloors, totalLifts);

            Console.WriteLine();
            String personCalledFloorConsole = personCalledFloor == 0 ? "G" : personCalledFloor.ToString();

            Console.WriteLine("You get in lift {0} and exit at floor {1}.", closestLift + 1, personCalledFloorConsole);

            return(buildingStructure);
        }
예제 #2
0
        static void Main(string[] args)
        {
            //Timer
            Stopwatch workTimer = new Stopwatch();

            workTimer.Start();

            //Initial input
            Console.WriteLine("Welcome to Gilmond HQ!\n");
            String userName    = UserInput.GetName();
            int    totalFloors = UserInput.Floors();
            int    totalLifts  = UserInput.Lifts();
            bool   isEmployee  = UserInput.IsEmployee();

            //User greeting
            if (isEmployee)
            {
                Employee user = new Employee(userName);
                Console.WriteLine();
                user.Greet();
            }
            else
            {
                Guest user = new Guest(userName);
                Console.WriteLine();
                user.Greet();
            }

            Console.WriteLine();
            Console.Write("Press any key to continue.");
            Console.ReadKey();
            Console.Clear();

            //Initialise Building
            String[][] buildingStructure = new string[totalFloors][];
            buildingStructure = Building.Construct(totalFloors, totalLifts);

            //Create list of Lift instances
            List <Lift> allLifts = LiftMethods.AllLiftsGenerator(totalFloors, totalLifts);

            buildingStructure = LiftMethods.LinkLifts(allLifts, buildingStructure, totalFloors, totalLifts);
            Building.Display(buildingStructure, totalFloors, totalLifts);

            bool isWorkingDay = true;

            while (isWorkingDay)
            {
                //Program loop
                Console.WriteLine();
                Menu.Display();
                int menuChoice = Menu.Action();
                Console.WriteLine();

                switch (menuChoice)
                {
                case 1:
                    //Call elevator
                    try
                    {
                        buildingStructure = Menu.CallElevator(allLifts, buildingStructure, totalFloors, totalLifts);
                    }
                    catch (InvalidOperationException)
                    {
                        Console.WriteLine("No lifts available, please wait for one to become available.");
                    }
                    break;

                case 2:
                    //View status
                    Menu.Status(allLifts);
                    break;

                case 3:
                    //Maintainence mode
                    Console.WriteLine("Welcome to Maintainence Mode");
                    buildingStructure = Menu.MaintainenceMode(buildingStructure, totalFloors, totalLifts, allLifts);
                    break;

                case 4:
                    //Exit program
                    isWorkingDay = false;
                    break;
                }
                Console.WriteLine();
                Console.Write("Press any key to continue.");
                Console.ReadKey();
                //Update display
                Console.Clear();
                buildingStructure = LiftMethods.LinkLifts(allLifts, buildingStructure, totalFloors, totalLifts);
                Building.Display(buildingStructure, totalFloors, totalLifts);
            }
            workTimer.Stop();
            var finalTimer = workTimer.Elapsed;

            //User farewell && Subtle subliminal messaging
            if (isEmployee)
            {
                Employee user = new Employee(userName);
                Console.WriteLine();
                user.Farewell(finalTimer);
            }
            else
            {
                Guest user = new Guest(userName);
                Console.WriteLine();
                user.Farewell(finalTimer);
            }
            Console.ReadLine();
        }