public IDriveable SetState(ICarState state) { Console.WriteLine("State has changed!"); _state = state; return(this); }
public void ChangeState(ICarState newState) { if (_state != null) { _state.stateFinished(); } _state = newState; _state.stateStarted(); }
public void Tune(int tuneIndex, string addOn) { _carState = _carState.Tune(() => { HorsePower += tuneIndex; Suspension = Suspension - tuneIndex / 2; TuneInternal(tuneIndex, addOn); }); }
public void Initialize(TrafficLight trafficLight) { CarWaitingState = new CarWaitingState(this); CarDriveForwardState = new CarDriveForwardState(this); _trafficLight = trafficLight; _currentState = CarDriveForwardState; _currentState.Enter(); }
private decimal Generate() { var rnd = new Random(); var value = (decimal)rnd.NextDouble() * 1000 + 200; if (value > 600) { State = new WarningCarState(); } return(value); }
protected Car(string brand, string model, int yearOfProduction, int horsePower, int acceleration, int suspension, int durability) { _carState = new CarAvailableState(); Brand = brand; Model = model; YearOfProduction = yearOfProduction; HorsePower = horsePower; Acceleration = acceleration; Suspension = suspension; Durability = durability; }
public Car(ICarState cs) { State = cs; }
public Car() { _currentState = new OffState(); }
public DieselCar() { State = new BrokenCarState(); }
public DieselCar(ICarState state) { State = state; }
public SmartCar() { State = new BrokenCarState(); }
public SmartCar(ICarState state) { State = state; }
public void EnterRace(Race race) { _carState = _carState.EnterRace(() => race.AddParticipant(this)); }
public ElectricCar() { State = new BrokenCarState(); }
public void Brake() { _currentState = _currentState.Brake(); }
/// <summary> /// Changes the state. /// </summary> /// <param name="stateId">The state identifier.</param> public void ChangeState(string stateId) { // Set thr current state CurrentState = _stateStore[stateId]; }
internal void SetState(ICarState state) { this.currentState = state; }
internal Car() { this.EcoState = new EcoState(this); this.currentState = this.EcoState; this.SportState = new SportState(this); }
public ElectricCar(ICarState state) { State = state; }
public void TurnKey() { _currentState = _currentState.TurnOn(); }
public void ChangeState(ICarState newstate) { _currentState = newstate; newstate.Enter(); }
public void Drive(string direction) { _currentState = _currentState.Drive(direction); }
public Car() { _state = new StopState(); }
public void TurnOff() { _currentState = _currentState.TurnOff(); }
/// <summary> /// Adds a state. /// </summary> /// <param name="stateId">The state identifier.</param> /// <param name="state">The state.</param> public void AddState(string stateId, ICarState state) { // Add the state to the collection _stateStore.Add(stateId, state); }