public static Car CreateCar(CarEnum car) { return(car switch { CarEnum.audi => new Audi(), CarEnum.bmw => new BMW(), _ => throw new Exception("沒有這個類別"), });;
public void SetCar(CarEnum carModel) { if (carModel != CarEnum.None) { HasCar = true; } CarModel = carModel; }
private void GetOnFerry() { if (Ferry.CanCarTakeAction(this)) { Console.WriteLine(string.Format("Car {0} get on the Ferry", Index)); //Ferry.GetCarIn(this); CarState = CarEnum.OnFerry; } WaitForAccess(); }
private void MoveFromFerry() { Console.WriteLine(string.Format("Car {0} get out of the Ferry", Index)); Thread.Sleep(500); CarState = CarEnum.WaitForFerry; Ferry.Cars.Pop(); Monitor.PulseAll(Ferry); }
private void GetOnFerry() { Console.WriteLine(string.Format("Car {0} get on the Ferry", Index)); Thread.Sleep(500); CarState = CarEnum.OnFerry; Ferry.Cars.Push(this); Monitor.PulseAll(Ferry); Monitor.Wait(Ferry); Drive(); }
public static Car Create(CarEnum carEnum) { switch (carEnum) { case CarEnum.BMW: return(new BmwCar()); case CarEnum.BYD: return(new BydCar()); default: return(null); } }
public Car() { CarThread = new Thread(new ThreadStart(Drive)); CarState = CarEnum.WaitForFerry; }
public Car() { CarThread = new Thread(new ThreadStart(Drive)); CarThread.Priority = ThreadPriority.BelowNormal; CarState = CarEnum.WaitForFerry; }