static void Main(string[] args) { //Receiver IVehicle car = new Car(); IVehicle motorcycle = new Motorcycle(); //Concrete commands ICommand turnOnCarCommand = new TurnOnVehicle(car); ICommand turnOffCarCommand = new TurnOffVehicle(car); ICommand speedUpCarCommand = new SpeedUpVehicle(car); ICommand brakeCarCommand = new BrakeVehicle(car); ICommand turnOnMotorcycleCommand = new TurnOnVehicle(motorcycle); ICommand turnOffMotorcycleCommand = new TurnOffVehicle(motorcycle); ICommand speedUpMotorcycleCommand = new SpeedUpVehicle(motorcycle); ICommand brakeMotorcycleCommand = new BrakeVehicle(motorcycle); //Invoker VehicleInvoker carInvoker = new VehicleInvoker(turnOnCarCommand, turnOffCarCommand, speedUpCarCommand, brakeCarCommand); VehicleInvoker motorcycleInvoker = new VehicleInvoker(turnOnMotorcycleCommand, turnOffMotorcycleCommand, speedUpMotorcycleCommand, brakeMotorcycleCommand); carInvoker.TurnOn(); carInvoker.SpeedUp(); carInvoker.Brake(); carInvoker.TurnOff(); motorcycleInvoker.TurnOn(); motorcycleInvoker.SpeedUp(); motorcycleInvoker.Brake(); motorcycleInvoker.TurnOff(); Console.ReadLine(); }
public void Start() { // Component Init if (vehicleData == null) { vehicleData = gameObject.GetComponent <VehicleData>(); } if (playerInput == null) { playerInput = gameObject.GetComponentInParent <InputController>(); } if (vehicleRB == null) { vehicleRB = gameObject.GetComponentInParent <Rigidbody>(); } if (wheelControllers.Length == 0) { wheelControllers = gameObject.GetComponentsInChildren <VehicleWheel>(); } airborneState = GetComponent <AirborneVehicle>(); tiltState = GetComponent <TiltVehicle>(); idleState = GetComponent <IdleVehicle>(); driveState = GetComponent <DriveVehicle>(); brakeState = GetComponent <BrakeVehicle>(); skidState = GetComponent <SkidVehicle>(); currentState = MovementState.Idle; ChangeState(); gravityForce = -Physics.gravity.y * (vehicleData.weight * 0.5f); }
static void Main(string[] args) { IVehicle car = new Car(); IVehicle motorcycle = new Motorcycle(); ICommand turnOnCommand = new TurnOnVehicle(car); ICommand turnOffCommand = new TurnOffVehicle(car); ICommand speedUpCommand = new SpeedUpVehicle(car); ICommand brakeCommand = new BrakeVehicle(car); ICommand turnOnMotorcycle = new TurnOnVehicle(motorcycle); ICommand turnOffMotorcycle = new TurnOffVehicle(motorcycle); ICommand speedUpMotorcycle = new SpeedUpVehicle(motorcycle); ICommand brakeMotorcycle = new BrakeVehicle(motorcycle); VehicleInvoker invoker = new VehicleInvoker(turnOnCommand, turnOffCommand, speedUpCommand, brakeCommand); VehicleInvoker motorclycleInvoker = new VehicleInvoker(turnOnMotorcycle, turnOffMotorcycle, speedUpMotorcycle, brakeMotorcycle); invoker.TurnOn(); invoker.SpeedUp(); invoker.Brake(); invoker.TurnOff(); motorclycleInvoker.TurnOn(); motorclycleInvoker.SpeedUp(); motorclycleInvoker.Brake(); motorclycleInvoker.TurnOff(); Console.ReadLine(); }
static void Main(string[] args) { //-- Receiver IVehicle car = new Car(); IVehicle bus = new Bus(); //-- Concrete commands ICommand turnOnCarCommand = new TurnOnVehicle(car); // for a command you need a ICommand turnOffCarCommand = new TurnOffVehicle(car); ICommand speedUpCarCommand = new SpeedUpVehicle(car); ICommand brakeCarCommand = new BrakeVehicle(car); ICommand turnOnBusCommand = new TurnOnVehicle(bus); ICommand turnOffBusCommand = new TurnOffVehicle(bus); ICommand speedUpBusCommand = new SpeedUpVehicle(bus); ICommand brakeBusCommand = new BrakeVehicle(bus); // (the order of the parameters must match that of the invoker) //-- Invoker / \ VehicleInvoker carInvoker = new VehicleInvoker(turnOnCarCommand, turnOffCarCommand, speedUpCarCommand, brakeCarCommand); VehicleInvoker busInvoker = new VehicleInvoker(turnOnBusCommand, turnOffBusCommand, speedUpBusCommand, brakeBusCommand); carInvoker.TurnOn(); carInvoker.SpeedUp(); carInvoker.Brake(); carInvoker.TurnOff(); busInvoker.TurnOn(); busInvoker.SpeedUp(); busInvoker.Brake(); busInvoker.TurnOff(); Console.ReadLine(); }
static void Main(string[] args) { IVehicle newVehicle = Vehicles.GetCar(); StartVehicle start = new StartVehicle(newVehicle); StopVehicle stop = new StopVehicle(newVehicle); BrakeVehicle brake = new BrakeVehicle(newVehicle); SpeedUpVehicle speedUp = new SpeedUpVehicle(newVehicle); CarInvoker carInvoker = new CarInvoker(start); carInvoker.InvokeCarCommand(); carInvoker = new CarInvoker(stop); carInvoker.InvokeCarCommand(); carInvoker = new CarInvoker(brake); carInvoker.InvokeCarCommand(); carInvoker = new CarInvoker(speedUp); carInvoker.InvokeCarCommand(); carInvoker.InvokeCarCommand(); carInvoker.InvokeCarCommand(); carInvoker.InvokeCarCommand(); carInvoker.InvokeCarCommand(); //---Notice MPH newVehicle = Vehicles.GetMotorcycle(); StartVehicle startMotorCycle = new StartVehicle(newVehicle); MotorcycleInvoker motorcycleInvoker = new MotorcycleInvoker(startMotorCycle); motorcycleInvoker.InvokeMotorcycleCommand(); }