Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        BaseFSM.FSM <StatesID> fsm = new BaseFSM.FSM <StatesID>("Main");

        /*************/

        //Main
        SwitchState stateOne = new SwitchState(StatesID.ONE)
        {
            isStart = true
        };

        stateOne.DefaultExit()
        .AddExitTransition(fsm, StatesID.FOUR);
        stateOne.AddTestExit(() => condition)
        .AddExitTransition(fsm, StatesID.TWO);

        SwitchState stateTwo = new SwitchState(StatesID.TWO);

        stateTwo.DefaultExit()
        .AddExitTransition(fsm, StatesID.FOUR);
        stateTwo.AddTestExit(() => condition)
        .AddExitTransition(fsm, StatesID.THREE);

        StableState stateThree = new StableState(StatesID.THREE);

        stateThree.AddAction("DoA", (o) => !condition, (o) => System.Console.WriteLine("action a"))
        .AddExitTransition(fsm, StatesID.ONE);
        stateThree.AddAction("DoB", (o) => condition, (o) => System.Console.WriteLine("action b"))
        .AddExitTransition(fsm, StatesID.FOUR);

        StateWithFSM stateFour = new StateWithFSM(StatesID.FOUR);

        stateFour.SubFSMExit()
        .AddExitTransition(fsm, StatesID.THREE);

        /////////////

        BaseFSM.Cursor <StatesID> cursor = fsm.GetCursor();
        System.Console.WriteLine(cursor);

        fsm.Start();
        System.Console.WriteLine(cursor);

        if (cursor.curState.id == StatesID.THREE)
        {
            cursor.DoAction("DoA");
        }
        System.Console.WriteLine(cursor);

        if (cursor.curState.id == StatesID.SUB_ONE)
        {
            cursor.DoAction("DoSubA");
        }
        System.Console.WriteLine(cursor);
    }
Ejemplo n.º 2
0
    public override void LoadFSM()
    {
        BaseFSM.FSM <StatesID> subFsm = new BaseFSM.FSM <StatesID>("Sub");
        subFsm.OnFinish += (x, y) => { System.Console.WriteLine("*** subFSM onFinish()"); };

        SetSubFSM(subFsm);

        StableState stateSubOne = new StableState(StatesID.SUB_ONE)
        {
            isStart = true
        };

        stateSubOne.AddAction("DoSubA", (o) => true, (o) => System.Console.WriteLine("sub action a"))
        .AddExitTransition(subFsm, StatesID.SUB_TWO);

        SwitchState stateSubTwo = new SwitchState(StatesID.SUB_TWO)
        {
            isFinish = true
        };

        subFsm.AddState(stateSubTwo);
    }
Ejemplo n.º 3
0
        FSM <STATE_ID> fsm;        //todo убрать! есть в стеке

        public Cursor(FSM <STATE_ID> fsm)
        {
            this.fsm = fsm;
            SetCursor();
        }
Ejemplo n.º 4
0
 public void AddExitTransition(FSM <STATE_ID> fsm, STATE_ID nextState)
 {
     fsm.AddStateExit(state, exitId, nextState);
 }
Ejemplo n.º 5
0
 public void OnSubFSMFinish(FSM <STATE_ID> fsm, STATE_ID state_id)
 {
     subFsm.OnFinish -= OnSubFSMFinish;
     DoExitState(subFSMExitID);
 }
Ejemplo n.º 6
0
 public void SetSubFSM(FSM <STATE_ID> subFsm)
 {
     this.subFsm      = subFsm;
     subFsm.OnFinish += OnSubFSMFinish;
 }