Ejemplo n.º 1
0
        /// <summary>
        /// create new tractor
        /// </summary>
        public override void CreateNewVehicle()
        {
            Tractor tractor = new Tractor
            {
                MotorVolume = Math.Round(rng.NextDouble() * 1000, 2),
                Weight      = rng.Next(1000, 2001),
                Category    = allCategory[rng.Next(0, allCategory.Length)],
                MotorType   = allMotorType[rng.Next(0, allMotorType.Length)],
                Color       = allColors[rng.Next(0, allColors.Length)],
                MotorNumber = rng.Next(50, 101),
                TireSize    = Math.Round(rng.NextDouble() * 100, 2),
                WheelBase   = rng.Next(2, 11),
                Drive       = allDrive[rng.Next(0, allDrive.Length)],
            };

            //add tractor to tractor list
            Program.allTractor.Add(tractor);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Automobile auto    = new Automobile();
            Tractor    tractor = new Tractor();
            Truck      truck   = new Truck();

            Race race = new Race();


            // Creating vehicles
            for (int i = 0; i < 2; i++)
            {
                auto.CreateNewVehicle();
                truck.CreateNewVehicle();
                tractor.CreateNewVehicle();
            }

            //stopwatch 5 seconds
            for (int i = 1; i < 6; i++)
            {
                Console.WriteLine(i);
                Thread.Sleep(1000);
            }

            // Starting cars
            for (int i = 0; i < allAutomobiles.Count; i++)
            {
                int    temp    = i;
                Thread thread1 = new Thread(() => race.Racing(allAutomobiles[temp]));
                thread1.Start();
            }

            // Creating orange golf car
            Random     rng  = new Random();
            Automobile golf = new Automobile
            {
                Color         = "Orange",
                MaxTankVolume = 51,
                Producer      = "Golf"
            };

            allAutomobiles.Add(golf);

            //check if there is red car in cars list
            for (int i = 0; i < allAutomobiles.Count; i++)
            {
                if (allAutomobiles[i].Color == "Red")
                {
                    isRedCar = true;
                    break;
                }
            }

            //Starting orange golf
            Console.WriteLine(golf.Color + " " + golf.Producer + " joined the race\n\n\n");
            Thread threadGolf = new Thread(() => race.Racing(golf));

            threadGolf.Start();

            //Thread that changes the semaphore color for 2 seconds
            Thread thread3 = new Thread(race.ChangeSemaphoreColor)
            {
                IsBackground = true
            };

            thread3.Start();

            // Thread that reduces the car Tank Volume every 1 second
            Thread thread4 = new Thread(race.DecreaseTankVolume)
            {
                IsBackground = true
            };

            thread4.Start();

            Console.ReadKey();
        }