/// <summary> /// Creates a specific tractor /// </summary> public override void Create() { 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)], }; Program.allTractor.Add(tractor); }
/// <summary> /// The main Method /// </summary> /// <param name="args">Main arguments</param> static void Main(string[] args) { Automobile auto = new Automobile(); Truck truck = new Truck(); Tractor tractor = new Tractor(); Raceing race = new Raceing(); // Creating vehicle objects for (int i = 0; i < 2; i++) { auto.Create(); truck.Create(); tractor.Create(); } // Countdown for (int i = 0; i < 6; i++) { Console.WriteLine(i); if (i == 5) { break; } Thread.Sleep(1000); } // Starting threads for (int i = 0; i < allAutomobiles.Count; i++) { // Because i is not thread safe due to being located on the same memory location for every thread and it is incremented all the time. int temp = i; Thread thread1 = new Thread(() => race.CarRaceProcess(allAutomobiles[temp])); thread1.Start(); } containsRedCar = Program.allAutomobiles.Any(car => car.Color == "Red"); // Creating golf car Random rng = new Random(); Automobile golf = new Automobile { Color = "Orange", TankVolume = 45, Producer = "Golf" }; allAutomobiles.Add(golf); // Starting golf Console.WriteLine(golf.Color + " " + golf.Producer + " joined the race\n\n--------------------------"); Thread thread2 = new Thread(() => race.CarRaceProcess(golf)); thread2.Start(); // Thread that changes the semaphore color every 2 seconds Thread thread3 = new Thread(race.ChangeSemaphoreColor) { IsBackground = true }; thread3.Start(); // Thread that reduces the Tank Volume every 1 second Thread thread4 = new Thread(race.TankDecrease) { IsBackground = true }; thread4.Start(); Console.ReadKey(); }