示例#1
0
        static void Main(string[] args)
        {
            var uber = new Park <Taxi>();

            Taxi taxi1 = new Taxi {
                currentLocation = new Location {
                    latDistance = 5, longDistance = 5, speed = 15
                }, number = "Car №1", status = Taxi.Status.Free
            };
            Taxi taxi2 = new Taxi {
                currentLocation = new Location {
                    latDistance = 15, longDistance = 5, speed = 25
                }, number = "Car №2", status = Taxi.Status.Free
            };
            Taxi taxi3 = new Taxi {
                currentLocation = new Location {
                    latDistance = 5, longDistance = 45, speed = 15
                }, number = "Car №3", status = Taxi.Status.Busy
            };
            Taxi taxi4 = new Taxi {
                currentLocation = new Location {
                    latDistance = 35, longDistance = 10, speed = 20
                }, number = "Car №4", status = Taxi.Status.Free
            };

            uber.Add(taxi1); uber.Add(taxi2); uber.Add(taxi3); uber.Add(taxi4);
            int x    = Convert.ToInt32(Console.ReadLine());
            int y    = Convert.ToInt32(Console.ReadLine());
            var linq = from t in uber.list orderby t.Way(x, y) select t;

            foreach (Taxi t in linq)
            {
                Console.WriteLine($"{t.Way(x, y)} тайла от {t.number}");
            }
            var min     = linq.Min(el => el.Way(x, y));
            var nearest = linq.FirstOrDefault(el => el.Way(x, y) == min);

            Console.WriteLine($"Такси {nearest.number} самое ближайшее к вызову. От неё до клиента {nearest.Way(x,y)} тайлов");
        }
示例#2
0
        static void Main(string[] args)
        {
            Park <Taxi> Uber = new Park <Taxi>();

            Uber.Add(new Taxi()
            {
                Number = "1", Position = new Location()
                {
                    Lat = 12.3439493f, Long = 483.129849384f, Speed = 63.2f
                }, Status = Stat.busy
            });
            Uber.Add(new Taxi()
            {
                Number = "2", Position = new Location()
                {
                    Lat = 42.3439493f, Long = 452.129849384f, Speed = 0f
                }, Status = Stat.free
            });
            Uber.Add(new Taxi()
            {
                Number = "3", Position = new Location()
                {
                    Lat = 22.3439493f, Long = 495.129849384f, Speed = 44.2f
                }, Status = Stat.free
            });
            Uber.Add(new Taxi()
            {
                Number = "4", Position = new Location()
                {
                    Lat = 17.3439493f, Long = 457.129849384f, Speed = 68f
                }, Status = Stat.busy
            });

            Console.WriteLine("---Введите свои координаты---");
            Location UserLocation = new Location();

            Console.Write("Широта: ");
            UserLocation.Lat = float.Parse(Console.ReadLine());
            Console.Write("Долгота: ");
            UserLocation.Long = float.Parse(Console.ReadLine());

            List <Taxi> taxis       = new List <Taxi>(Uber.park);
            var         TaxisToUser = taxis.OrderBy(x => Math.Sqrt(Math.Pow(x.Position.Lat - UserLocation.Lat, 2) + Math.Pow(x.Position.Long - UserLocation.Long, 2)));

            foreach (var taxi in TaxisToUser)
            {
                Console.WriteLine(taxi.Number);
            }

            using (FileStream sw = new FileStream("Taxi.bin", FileMode.Create))
            {
                //XmlSerializer xml = new XmlSerializer(TaxisToUser.First().GetType());
                //xml.Serialize(sw, TaxisToUser.First());
                BinaryFormatter bin = new BinaryFormatter();
                bin.Serialize(sw, TaxisToUser.First());
            }



            //Task 2
            Program2.Task2();
            Console.ReadKey();
        }