示例#1
0
        /// <summary>
        /// The tram has departed from this stop, to the next stop.
        /// </summary>
        /// <param name="state"></param>
        protected override void ExecuteEvent(WorldState state)
        {
            // Tram arrives at queue
            StopState stopState = state.GetStopState(stop);

            this.scheduleEvent(new DepartStopEvent(tram, stop.NextStop, scheduler), 80);
        }
示例#2
0
    private void Awake()
    {
        manager = GameObject.Find("ManagerObj").GetComponent <SingletonAudio>();

        inspirationState = new InspirationState(this);
        composingState   = new ComposingState(this);
        stopState        = new StopState(this);
    }
示例#3
0
 private StopState()
 {
     if (_instance != null)
     {
         return;
     }
     _instance = this;
 }
        protected override void ExecuteEvent(WorldState state)
        {
            StopState stopState = state.GetStopState(stop);

            stopState.Passengers += calculatePassengers();

            scheduleEvent(new PassengerArriveEvent(stop, scheduler), calculateNextSchedule());
        }
示例#5
0
    public static void StatePatternDemo()
    {
        // we can think of it as finite state machine
        State startState = new StartState();
        State stopState  = new StopState();

        Context context = new Context();

        startState.DoAction(context);

        stopState.DoAction(context);
    }
     protected void Toggle()
     {
         Lights = Lights switch
         {
             StopState _ => new GetReadyToGoState(),
             GetReadyToGoState _ => new GoState(),
             GoState _ => new GetReadyToStopState(),
             GetReadyToStopState _ => new StopState(),
                       _ => throw new ArgumentOutOfRangeException(nameof(Lights))
         };
     }
 }
示例#7
0
    public void Main()
    {
        Context context = new Context();

        StartState startState = new StartState();

        startState.DoAction(context);
        Console.WriteLine(context.GetState().ToString());

        StopState stopState = new StopState();

        stopState.DoAction(context);
        Console.WriteLine(context.GetState().ToString());
    }
示例#8
0
    void Start()
    {
        IdleState     idle    = new IdleState(PlayerState.Idle, this);
        ReadyState    ready   = new ReadyState(PlayerState.Ready, this);
        FightingState fight   = new FightingState(PlayerState.Fighting, this);
        StopState     stop    = new StopState(PlayerState.Stop, this);
        SuccessState  success = new SuccessState(PlayerState.Success, this);
        DeathState    death   = new DeathState(PlayerState.Death, this);

        Machine = new StateMachine(idle);
        Machine.AddState(ready);
        Machine.AddState(fight);
        Machine.AddState(stop);
        Machine.AddState(success);
        Machine.AddState(death);
    }
        public void StopStateTest()
        {
            var state = new StopState();

            robot.Acceleration = 3.0;
            robot.Speed        = 2.0;
            brain.CurrentState = state;
            env.Tick();
            Assert.NotEqual(0.0, robot.Acceleration, 3);
            for (int i = 0; i < 5; i++)
            {
                env.Tick();
            }
            Assert.Equal(0.0, robot.Acceleration, 3);
            Assert.Equal(0.0, robot.Speed, 3);
            Assert.IsType <IdleState>(brain.CurrentState);
        }
        static void Main(string[] args)
        {
            Context context = new Context();

            StartState startState = new StartState();

            startState.DoAction(context);

            Console.WriteLine(context.State.ToString());

            StopState stopState = new StopState();

            stopState.DoAction(context);

            Console.WriteLine(context.State.ToString());

            Console.ReadLine();
        }
示例#11
0
        private void btStatePattern_Click(object sender, EventArgs e)
        {
            string str = "";

            StatePattern.Context context = new StatePattern.Context();

            StartState startState = new StartState();

            str += startState.doAction(context) + "\r\n";

            str += context.getState().ToString() + "\r\n";

            StopState stopState = new StopState();

            str += stopState.doAction(context) + "\r\n";

            str += context.getState().ToString() + "\r\n";
            tbOutWindow.Text = str;
        }
示例#12
0
    void Start()
    {
        _navMeshAgent  = GetComponent <NavMeshAgent>();
        _renderer      = GetComponent <Renderer>();
        _originalColor = _renderer.material.color;

        _stateMachine = new FiniteStateMachine <GuardFSM>(this);

        //STATES
        State patrolState = new PatrolState("Patrol", this);
        State chaseState  = new ChaseState("Chase", this);
        State stopState   = new StopState("Stop", this);

        //TRANSITIONS
        _stateMachine.AddTransition(patrolState, chaseState, () => DistanceFromTarget() <= _minChaseDistance);
        _stateMachine.AddTransition(chaseState, patrolState, () => DistanceFromTarget() > _minChaseDistance);
        _stateMachine.AddTransition(chaseState, stopState, () => DistanceFromTarget() <= _stoppingDistance);
        _stateMachine.AddTransition(stopState, chaseState, () => DistanceFromTarget() > _stoppingDistance);

        //START STATE
        _stateMachine.SetState(patrolState);
    }
 protected override void CreateStates()
 {
     StatePreRun = new PreRunState(this);
     StateRun = new RunState(this);
     StatePreStop = new PreStopState(this);
     StateStop = new StopState(this);
     StatePreInitialize = new PreInitializeState(this);
     StateInitialize = new InitializeState(this);
     StateRundown = new RundownState(this);
     StatePreEmergency = new PreEmergencyState(this);
     StateEmergency = new EmergencyState(this);
     StateEmergencyReset = new EmergencyResetState(this);
     StatePreAlarm = new PreAlarmState(this);
     StateAlarm = new AlarmState(this);
     StatePreWarning = new PreWarningState(this);
     StateWarning = new WarningState(this);
     StatePreSuspend = new PreSuspendState(this);
     StateSuspend = new SuspendState(this);
 }