static void Main(string[] args) { IVehicleFactory factory = new BusFactory(); ABus[] busses = factory.CreateVehicles(4); Object time = new BusTime(ushort.MaxValue, 100); Run(busses, time); Console.ReadLine(); }
public override void Run(object time) { Console.WriteLine($"Current fuel is: {Fuel.ToString()}"); BusTime busTime = (BusTime)time; DateTime now = new DateTime(); DateTime target = now.AddMilliseconds(busTime.Duration); UInt16 numberOfTicks = (ushort)((target.Millisecond - now.Millisecond) / busTime.Timestep); if (!Started && Fuel >= 0f) { Start(); } else if (Fuel == 0f) { OnFuelEmpty(this, new EngineEventArgs { Stopped = true }); } else { while (now < target) { for (int i = 0; i < numberOfTicks; i++) { Thread.Sleep(busTime.Timestep); CalculateFuelConsumption(); Fuel -= 60; if (Fuel == 0) { OnFuelEmpty(this, new EngineEventArgs { Stopped = true }); break; } } } } Console.WriteLine($"Current fuel is: {Fuel.ToString()}"); Console.WriteLine($"Finnished running on DieselEngine, on thread : {Thread.CurrentThread.Name.ToString()}!"); }
public override void Drive(object time) { BusTime busTime = (BusTime)time; EngineThread.Start(time); Console.WriteLine($"Current people in bus are: { People.Count}"); DateTime target = new DateTime(); target = DateTime.Now.AddMilliseconds(busTime.Duration); UInt16 numberOfTicks = (ushort)((target.Millisecond - DateTime.Now.Millisecond) / busTime.Timestep); Random rnd = new Random(654668); while (DateTime.Now.Millisecond < target.Millisecond) { for (int i = 0; i < numberOfTicks; i++) { double temp = rnd.NextDouble(); //Thread.Sleep(busTime.Timestep); if (temp >= 0.5) { APerson person = new Adult(); // person.stop = new Stop() person.Ticket = person.BuyTicket(person); person.BusEntrance = (IEnterable)this; bool canjoin = person.BusEntrance.CanEnter(person.Ticket); if (canjoin) { person.Ticket.RegisterEntrance(this); } } } } Console.WriteLine($"Current people in bus are: { People.Count}"); //Thread.Sleep(Convert.ToInt32(busTime.Timestep)); }