コード例 #1
0
ファイル: Program.cs プロジェクト: evglaptev/Elevator
 public HumanGenerator(double refreshHuman, Floor[] Floors)
 {
     RefreshHuman = refreshHuman;
     this.Floors = Floors;
     LastCreate = Time.Current;
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: evglaptev/Elevator
 public ElevatorManager(int level, int ElevatorCount, Floor[] floors)
 {
     Floors = floors;
     LevelCount = level;
     Task = new List<int>();
     this.ElevatorCount = ElevatorCount;
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: evglaptev/Elevator
            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++;

                }
            }
コード例 #4
0
ファイル: Program.cs プロジェクト: evglaptev/Elevator
        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();
        }