예제 #1
0
        public IDriveable SetState(ICarState state)
        {
            Console.WriteLine("State has changed!");
            _state = state;

            return(this);
        }
예제 #2
0
    public void ChangeState(ICarState newState)
    {
        if (_state != null) {
            _state.stateFinished();
        }

        _state = newState;
        _state.stateStarted();
    }
예제 #3
0
 public void Tune(int tuneIndex, string addOn)
 {
     _carState = _carState.Tune(() =>
     {
         HorsePower += tuneIndex;
         Suspension  = Suspension - tuneIndex / 2;
         TuneInternal(tuneIndex, addOn);
     });
 }
예제 #4
0
    public void Initialize(TrafficLight trafficLight)
    {
        CarWaitingState      = new CarWaitingState(this);
        CarDriveForwardState = new CarDriveForwardState(this);

        _trafficLight = trafficLight;

        _currentState = CarDriveForwardState;
        _currentState.Enter();
    }
예제 #5
0
        private decimal Generate()
        {
            var rnd   = new Random();
            var value = (decimal)rnd.NextDouble() * 1000 + 200;

            if (value > 600)
            {
                State = new WarningCarState();
            }

            return(value);
        }
예제 #6
0
        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;
        }
예제 #7
0
 public Car(ICarState cs)
 {
     State = cs;
 }
예제 #8
0
 public Car()
 {
     _currentState = new OffState();
 }
예제 #9
0
 public DieselCar()
 {
     State = new BrokenCarState();
 }
예제 #10
0
 public DieselCar(ICarState state)
 {
     State = state;
 }
예제 #11
0
 public SmartCar()
 {
     State = new BrokenCarState();
 }
예제 #12
0
 public SmartCar(ICarState state)
 {
     State = state;
 }
예제 #13
0
 public void EnterRace(Race race)
 {
     _carState = _carState.EnterRace(() =>
                                     race.AddParticipant(this));
 }
예제 #14
0
 public ElectricCar()
 {
     State = new BrokenCarState();
 }
예제 #15
0
 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];
 }
예제 #17
0
 internal void SetState(ICarState state)
 {
     this.currentState = state;
 }
예제 #18
0
 internal Car()
 {
     this.EcoState     = new EcoState(this);
     this.currentState = this.EcoState;
     this.SportState   = new SportState(this);
 }
예제 #19
0
 public ElectricCar(ICarState state)
 {
     State = state;
 }
예제 #20
0
 public void TurnKey()
 {
     _currentState = _currentState.TurnOn();
 }
예제 #21
0
 public void ChangeState(ICarState newstate)
 {
     _currentState = newstate;
     newstate.Enter();
 }
예제 #22
0
 public void Drive(string direction)
 {
     _currentState = _currentState.Drive(direction);
 }
예제 #23
0
 public Car()
 {
     _state = new StopState();
 }
예제 #24
0
 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);
 }