Esempio n. 1
0
    private void Awake()
    {
        _idle          = new WsState("idle");
        _idle.OnEnter += (IState state) =>
        {
            print("进入idle状态");
        };
        _idle.OnUpdate += (float f) => { print("idle中"); };

        _move           = new WsState("move");
        _move.OnEnter  += (IState state) => { print("进入move状态"); };
        _move.OnUpdate += (float f) =>
        {
            transform.position += transform.forward * f * speed;
            print("move 了一下");
        };

        _idleMove          = new WsTransition("idelMove", _idle, _move);
        _idleMove.OnCheck += () =>
        {
            return(_isMove);
        };
        _idle.AddTransition(_idleMove);

        _moveIdle          = new WsTransition("moveIdle", _move, _idle);
        _moveIdle.OnCheck += () =>
        {
            return(!_isMove);
        };
        _move.AddTransition(_moveIdle);

        _fsm = new WsStateMachine("root", _idle);
        _fsm.AddState(_move);
    }
Esempio n. 2
0
        private void InitFsm()
        {
            #region 资源初始化
            _preparingState = new WsState("preparing");
            //_preparingState.OnUpdate += InitGame;
            #endregion

            #region 洗牌中
            _shufflingState           = new WsState("shuffling");
            _shufflingState.OnEnter  += GetShufTime;
            _shufflingState.OnUpdate += Shuffle;
            _shufflingState.OnExit   += (IState state) => { _isShuffled = false; };

            _bettingState           = new WsState("betting");
            _bettingState.OnEnter  += Start1Round;
            _bettingState.OnUpdate += Bet;
            _bettingState.OnExit   += RoundOrSessionOver;

            _prepareShuffle = new WsTransition("preShuffle", _preparingState, _shufflingState);
            _prepareShuffle.OnTransition += InitGame;
            _prepareShuffle.OnCheck      += GameInited;
            _preparingState.AddTransition(_prepareShuffle);

            _shuffleBet          = new WsTransition("shuffleBet", _shufflingState, _bettingState);
            _shuffleBet.OnCheck += Shuffled;
            _shufflingState.AddTransition(_shuffleBet);
            #endregion


            #region 开始押注

            //开下一局
            _betNextBet          = new WsTransition("betNextBet", _bettingState, _bettingState);
            _betNextBet.OnCheck += CanGoNextBet;
            //_betNextBet.OnTransition += DealCard;	//开牌动画,结算筹码
            _bettingState.AddTransition(_betNextBet);

            //本场结束,验单,重新洗牌
            _betShuffle               = new WsTransition("betShuffle", _bettingState, _shufflingState);
            _betShuffle.OnCheck      += SessionOver;
            _betShuffle.OnTransition += ExamineWaybill;
            _bettingState.AddTransition(_betShuffle);
            #endregion

            #region 押注结束后亮牌结算
            //_accountingState = new WsState("accounting");
            //_accountingState.OnEnter += GetAccountTime;
            //_accountingState.OnUpdate += Account;
            //_accountingState.OnExit += (IState s) => { _isAccounted = false; };

            ////直接开下局押注
            //_accountBet = new WsTransition("accountBet", _accountingState, _bettingState);
            //_accountBet.OnCheck += RoundAccounted;
            //_accountingState.AddTransition(_accountBet);

            ////每场最后局结束,要重新洗牌
            //_accountShuffle = new WsTransition("accountShuffle", _accountingState, _shufflingState);
            //_accountShuffle.OnCheck += SessionAccounted;
            //_accountingState.AddTransition(_accountShuffle);
            #endregion

            _fsm = new WsStateMachine("baccarat", _preparingState);
            _fsm.AddState(_preparingState);
            _fsm.AddState(_shufflingState);
            _fsm.AddState(_bettingState);
            //_fsm.AddState(_accountingState);
            print("init fsm over");
        }
Esempio n. 3
0
        private void InitFsm()
        {
            _preparingState = new WsState("preparing");
            _shufflingState = new WsState("shuffling");
            _printingState  = new WsState("printing");
            _bettingState   = new WsState("betting");
            _dealingState   = new WsState("dealing");
            _examineState   = new WsState("examine");

            //初始化切换到洗牌
            _prepareShuffle          = new WsTransition("preShuffle", _preparingState, _shufflingState);
            _prepareShuffle.OnCheck += () => { return(true); };
            _preparingState.AddTransition(_prepareShuffle);

            //洗牌切换到打印
            _shufflingState.OnEnter  += OnShuffleEnter;
            _shufflingState.OnUpdate += OnShufflling;
            _shufflingState.OnExit   += OnShuffleExit;
            _shuffleBet          = new WsTransition("shufflePrint", _shufflingState, _printingState);
            _shuffleBet.OnCheck += IsShuffled;
            _shufflingState.AddTransition(_shuffleBet);

            //打印切换到押注
            _printingState.OnEnter  += _printingState_OnEnter;
            _printingState.OnUpdate += _printingState_OnUpdate;
            _printingState.OnExit   += _printingState_OnExit;
            _printBet          = new WsTransition("printBet", _printingState, _bettingState);
            _printBet.OnCheck += () => { return(_isPrinted); };
            _printingState.AddTransition(_printBet);

            //押注切换到开牌
            _bettingState.OnEnter  += OnBetEnter;
            _bettingState.OnUpdate += Betting;
            _bettingState.OnExit   += OnBetExit;
            _betDeal          = new WsTransition("betDeal", _bettingState, _dealingState);
            _betDeal.OnCheck += IsBetted;
            _bettingState.AddTransition(_betDeal);

            //开牌后切换到下一轮
            _dealingState.OnEnter     += OnDealEnter;
            _dealingState.OnUpdate    += Dealing;
            _dealingState.OnExit      += OnDealExit;
            _dealNextBet               = new WsTransition("dealNextBet", _dealingState, _bettingState);
            _dealNextBet.OnCheck      += CanGoNextBet;
            _dealNextBet.OnTransition += GotoNextBet;

            //开牌后本局结束,验单,重新洗牌,切换到下一局
            _dealExamine          = new WsTransition("dealExamine", _dealingState, _examineState);
            _dealExamine.OnCheck += IsSessionOver;
            _dealingState.AddTransition(_dealNextBet);
            _dealingState.AddTransition(_dealExamine);

            //验单
            _examineState.OnEnter   += OnExamineEnter;
            _examineState.OnUpdate  += OnExamining;
            _examineState.OnExit    += OnExamineExit;
            _examineShuffle          = new WsTransition("examineShuffle", _examineState, _shufflingState);
            _examineShuffle.OnCheck += IsExamineOver;
            _examineState.AddTransition(_examineShuffle);

            _fsm = new WsStateMachine("baccarat", _preparingState);
            _fsm.AddState(_preparingState);
            _fsm.AddState(_shufflingState);
            _fsm.AddState(_bettingState);
            _fsm.AddState(_dealingState);
            _fsm.AddState(_examineState);
        }