Пример #1
0
            static void Main(string[] args)
            {
                Elevator elevator = new Elevator();
                elevator.Floor = 1;
                do
                {
                    Console.WriteLine("You are on floor number " + elevator.Floor);
                    Console.WriteLine("Enter new floor:  ");
                    elevator.Floor = int.Parse(Console.ReadLine());
                } while (true);


            }
Пример #2
0
        static void Main(string[] args)
        {
            Elevator hissi = new Elevator();

       
            bool kalle = true;
            while(kalle) {
                string elvis = Console.ReadLine();
                switch (elvis)
            {
                case "+": hissi.Ylos();  break;
                case "-": hissi.Alas();  break;
                default: kalle = false; break;

            }
            }
          
           
        }
Пример #3
0
        public Elevator ElevatorCheck(Person person, List <Elevator> suitableElevators)
        {
            Elevator SuitableElevator = new Elevator();
            int      suitable         = 0;

            if (person.Direction == Status.Down)
            {
                suitable = _topFloor;
            }
            else if (person.Direction == Status.Up)
            {
                suitable = _botFloor;
            }
            foreach (var elevator in suitableElevators)
            {
                int res = 0;
                if (person.Location > elevator.CurrentFloor)
                {
                    res = person.Location - elevator.CurrentFloor;
                }
                else
                {
                    res = elevator.CurrentFloor - person.Location;
                }
                if (suitableElevators.Count == 1)
                {
                    return(elevator);
                }
                if (res <= suitable)
                {
                    suitable         = res;
                    SuitableElevator = elevator;
                }
            }
            return(SuitableElevator);
        }
Пример #4
0
            public void Update()
            {
                if (status == 0)
                {
                    if (floor != null)
                    {
                        if (!floor.Button)
                        {
                            PressButton();
                        }

                        elevator = floor.GetElevator();

                        if (elevator != null)
                        {
                            elevator.AddHuman(this);
                            floor = null;
                            status = 1;
                            log.Write(DateTime.Now.Minute + ":" + DateTime.Now.Second + " - ");
                            log.WriteLine("Status = 1");
                        }
                    }
                }
                else if (status == 1)
                {
                    if (elevator != null)
                    {
                        elevator.PressButton(FinishLevel);
                        status = 2;
                        log.Write(DateTime.Now.Minute + ":" + DateTime.Now.Second + " - ");
                        log.WriteLine("Человек нажал на кнопку " + FinishLevel + " в лифте.");
                    }
                } else if (status == 2)
                {
                    floor = elevator.getFloor();

                    if (Math.Abs(elevator.CorrentLevel - FinishLevel) <= eps)
                    {
                        elevator.DeleteHuman(this);
                        log.Write(DateTime.Now.Minute + ":" + DateTime.Now.Second + " - ");
                        log.WriteLine("Человек вышел из лифта");
                        //floor.AddHuman(this);
                        status = 3;
                    }

                }
                else if (status == 3)
                {
                         floor.deleteHuman(this);
                    status++;

                }
            }
Пример #5
0
 internal Floor GetFloor(Elevator elevator)
 {
     return Floors[(int)Math.Round(elevator.CorrentLevel)];
 }
Пример #6
0
 public void AddElevators(Elevator[] elevators)
 {
     this.elevators = elevators;
 }
Пример #7
0
        public static void Main()
        {
            List<int> list = new List<int>();
            for (var i = 0; i < 10; i++)
            {
                list.Add(i);
            }

            // method 1
            for (var i = list.Count - 1; i >= 0; i--)
                if (false)
                    list.RemoveAt(i);

            // method 2 - linq
            List<int> result;
            result = (from el in list
                      where el < 5
                      select el).ToList();

            var list2 = new List<string> { "1", "2", "hello", "world" };

            // method 2 - linq 2
            result = list.Where(el => el < 5).ToList();
            result = list2.Where(el => { int o; return int.TryParse(el, out o); })
                          .Select(el => int.Parse(el))
                          .ToList();

            Time.Start();
            Floor[] levels = new Floor[LevelCount];
            var manager = new ElevatorManager(LevelCount, ElevatorCount,levels);
            for (var i = 0; i < LevelCount; i++)
            {
                Floor TmpFloor = new Floor(manager, i);
                levels[i] = TmpFloor;
            }
            Elevator[] elevators = new Elevator[ElevatorCount];
            manager.AddElevators(elevators);

            var humanGenerator = new HumanGenerator(RefreshHuman, levels);

            for (var i = 0; i < ElevatorCount; i++)
                elevators[i] = new Elevator(manager);

            DateTime startData = DateTime.Now;

            Console.WriteLine(startData.Ticks/10000000);
               // Console.ReadKey();

            while ((DateTime.Now-startData).Ticks/10000000 < 20)
            {

                //log.WriteLine("humangeneratorUpdate"+ elevators[0].CorrentLevel);
                humanGenerator.Update();
                //log.WriteLine("managerupdate"+ elevators[0].CorrentLevel);
                manager.Update();
                for (var i = 0; i < ElevatorCount; i++)
                    if (elevators[i].Humans != null)
                        for (var j = 0; j < elevators[i].Humans.Count; j++)
                            elevators[i].Humans[j].Update();

                foreach (var floor in levels) {
                    foreach (var human in floor.Queue)
                        human.Update();
                    }
                // log.WriteLine("elevatorUpdate"+ elevators[0].CorrentLevel);

                //System.Threading.Thread.Sleep(5);
                for (var i = 0; i < ElevatorCount; i++)
                {
                    elevators[i].Update();
                }
            }
            log.Dispose();
        }