当前位置: 首页>>代码示例>>C#>>正文


C# StateMachine.AddTransition方法代码示例

本文整理汇总了C#中StateMachine.AddTransition方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.AddTransition方法的具体用法?C# StateMachine.AddTransition怎么用?C# StateMachine.AddTransition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StateMachine的用法示例。


在下文中一共展示了StateMachine.AddTransition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test1

        public void Test1()
        {
            #region Creating the state machine instance called machine
            var machine = new StateMachine<States>();

            machine.AddState(States.R);
            machine.AddState(States.G);
            machine.AddState(States.B);

            machine.AddTransition(States.R, States.G);
            machine.AddTransition(States.G, States.B);
            #endregion

            string EnteringCallbackMsg = "", ExitingCallbackMsg = "", TransistionCallback = "";
            string TransitingEventMsg = "", TransitedEventMsg = "";

            #region Adding callbacks to machine
            Action<States> EnteringCallback = (state) => EnteringCallbackMsg = String.Format("Entering state {0}", state);
            machine.AddEnterStateCallback(States.R, EnteringCallback.Invoke);
            machine.AddEnterStateCallback(States.G, EnteringCallback.Invoke);
            machine.AddEnterStateCallback(States.B, EnteringCallback.Invoke);

            Action<States> ExitingCallback = (state) => ExitingCallbackMsg = String.Format("Exiting state {0}", state);
            machine.AddExitStateCallback(States.R, ExitingCallback.Invoke);
            machine.AddExitStateCallback(States.G, ExitingCallback.Invoke);
            machine.AddExitStateCallback(States.B, ExitingCallback.Invoke);

            Action<States, States> TransitionCallback = (from, to) => TransistionCallback = String.Format("Going from {0} to {1}", from, to);
            machine.AddTransitionCallback(States.R, States.G, TransitionCallback.Invoke);
            machine.AddTransitionCallback(States.G, States.B, TransitionCallback.Invoke);
            #endregion

            #region Adding events to machine
            machine.Transiting += new EventHandler<TransitingEventArgs<States>>((s, e) => TransitingEventMsg = String.Format("Event Fired: Transiting into state {0}", e.State));
            machine.Transited  += new EventHandler<TransitedEventArgs<States>>( (s, e) => TransitedEventMsg  = String.Format("Event Fired: Transited into state {0}", e.State));
            #endregion

            #region Testing machine
            Assert.AreEqual(machine.CurrentState, null);

            machine.GoToState(States.R);
            Assert.AreEqual(machine.CurrentState.Name, States.R);
            Assert.AreEqual(ExitingCallbackMsg, "");
            Assert.AreEqual(TransistionCallback, "");
            Assert.AreEqual(EnteringCallbackMsg, "Entering state R");
            Assert.AreEqual(TransitingEventMsg, "Event Fired: Transiting into state R");
            Assert.AreEqual(TransitedEventMsg, "Event Fired: Transited into state R");

            machine.GoToState(States.G);
            Assert.AreEqual(machine.CurrentState.Name, States.G);
            Assert.AreEqual(ExitingCallbackMsg, "Exiting state R");
            Assert.AreEqual(TransistionCallback, "Going from R to G");
            Assert.AreEqual(EnteringCallbackMsg, "Entering state G");
            Assert.AreEqual(TransitingEventMsg, "Event Fired: Transiting into state G");
            Assert.AreEqual(TransitedEventMsg, "Event Fired: Transited into state G");

            machine.GoToState(States.B);
            Assert.AreEqual(machine.CurrentState.Name, States.B);
            Assert.AreEqual(ExitingCallbackMsg, "Exiting state G");
            Assert.AreEqual(TransistionCallback, "Going from G to B");
            Assert.AreEqual(EnteringCallbackMsg, "Entering state B");
            Assert.AreEqual(TransitingEventMsg, "Event Fired: Transiting into state B");
            Assert.AreEqual(TransitedEventMsg, "Event Fired: Transited into state B");
            #endregion
        }
开发者ID:sdenel,项目名称:StateMachine,代码行数:65,代码来源:Program.cs

示例2: CreateStateMachine

    private void CreateStateMachine()
    {
        stateMachine = new StateMachine("MainMenu");

        ActionState waiting = stateMachine.AddActionState("Waiting", null, null, null);
        ActionState onePlayer = stateMachine.AddActionState("OnePlayer", OnPlayer_Enter, null, null);
        ActionState twoPlayer = stateMachine.AddActionState("TwoPlayer", TwoPlayer_Enter, null, null);
        ActionState puzzle = stateMachine.AddActionState("Puzzle", Puzzle_Enter, null, null);
        ActionState stateTutorial = stateMachine.AddActionState("Tutorial", Tutorial_Enter, null, null);

        showDifficulty = stateMachine.AddActionState("ShowDifficulty", ShowDifficulty_Enter, null, null);
        ActionState backPlayingMode = stateMachine.AddActionState("BackPlayingMode", BackPlayingMode_Enter, null, null);

        ActionState easy = stateMachine.AddActionState("Easy", Easy_Enter, null, null);
        ActionState normal = stateMachine.AddActionState("Normal", Normal_Enter, null, null);
        ActionState difficult = stateMachine.AddActionState("Difficult", Difficult_Enter, null, null);

        stateMachine.AddTransition(waiting, onePlayer, IsOnePlayerClicked);
        stateMachine.AddTransition(waiting, twoPlayer, IsTwoPlayerClicked);
        stateMachine.AddTransition(waiting, puzzle, IsPuzzleClicked);

        stateMachine.AddTransition(onePlayer, showDifficulty, () => { return true; });
        stateMachine.AddTransition(twoPlayer, showDifficulty, () => { return true; });
        stateMachine.AddTransition(puzzle, showDifficulty, () => { return true; });

        stateMachine.AddTransition(showDifficulty, easy, IsEasyClicked);
        stateMachine.AddTransition(showDifficulty, normal, IsNormalClicked);
        stateMachine.AddTransition(showDifficulty, difficult, IsDifficultClicked);
        stateMachine.AddTransition(showDifficulty, backPlayingMode, IsBackPressed);

        stateMachine.AddTransition(backPlayingMode, waiting, () => { return true; });

        stateMachine.AddTransition(stateTutorial, IsTutorialClicked);

        stateMachine.CurrentState = waiting;
    }
开发者ID:nicolas-repiquet,项目名称:FoodTruckSaga,代码行数:36,代码来源:MainMenu.cs

示例3: CreateStateMachineClient

    private void CreateStateMachineClient()
    {
        StateMachineClient = new StateMachine("Gameplay");

        initialLoading = StateMachineClient.AddActionState("InitialLoading", null, null, null);
        initialLoadingPuzzle = StateMachineClient.AddActionState("InitialLoadingPuzzle", InitialLoadingPuzzle_Enter, null, null);
        waitingCommand = StateMachineClient.AddActionState("WaitingCommand", WaitingCommand_Enter, null, null);
        warning = StateMachineClient.AddActionState("Warning", Warning_Enter, null, null);
        checkCommand = StateMachineClient.AddActionState("CheckCommand", CheckCommand_Enter, null, null);
        checkCommandPuzzle = StateMachineClient.AddActionState("CheckCommandPuzzle", CheckCommandPuzzle_Enter, null, null);
        animSandwich = StateMachineClient.AddActionState("AnimSandwich", AnimSandwich_Enter, null, AnimSandwich_Exit);
        nextclient = StateMachineClient.AddActionState("NextClient", NextClient_Enter, null, null);
        nextclientPuzzle = StateMachineClient.AddActionState("NextClientPuzzle", NextClientPuzzle_Enter, null, null);
        backToMainMenu = StateMachineClient.AddActionState("BackToMainMenu", BackToMainMenu_Enter, null, null);

        if (Repository.Instance.Puzzle)
        {
            StateMachineClient.AddTransition(initialLoadingPuzzle, waitingCommand, IsClientReady);
            StateMachineClient.AddTransition(waitingCommand, checkCommandPuzzle, IsCheckCommandPuzzle);
            StateMachineClient.AddTransition(checkCommandPuzzle, animSandwich, TrueCondition);
            StateMachineClient.AddTransition(animSandwich, nextclientPuzzle, IsAnimSandwichFinished);
            StateMachineClient.AddTransition(nextclientPuzzle, waitingCommand, IsClientReady);
            StateMachineClient.AddTransition(backToMainMenu, IsBackToMainMenu);

            StateMachineClient.CurrentState = initialLoadingPuzzle;
            InitialLoadingPuzzle_Enter();
        }
        else
        {
            StateMachineClient.AddTransition(initialLoading, waitingCommand, IsClientReady);
            StateMachineClient.AddTransition(waitingCommand, warning, IsWarning);
            StateMachineClient.AddTransition(warning, checkCommand, IsCheckCommand);
            StateMachineClient.AddTransition(checkCommand, animSandwich, TrueCondition);
            StateMachineClient.AddTransition(animSandwich, nextclient, IsAnimSandwichFinished);
            StateMachineClient.AddTransition(nextclient, waitingCommand, IsClientReady);
            StateMachineClient.AddTransition(backToMainMenu, IsBackToMainMenu);

            StateMachineClient.CurrentState = initialLoading;
        }
    }
开发者ID:nicolas-repiquet,项目名称:FoodTruckSaga,代码行数:40,代码来源:GamePlayManager.cs

示例4: CreateStateMachine

    private void CreateStateMachine()
    {
        _stateMachine = new StateMachine("PlayerHuman " + PlayerIndex);

        playing = _stateMachine.AddActionState("Playing", null, null, null);
        createSandwich = _stateMachine.AddActionState("CreateSandwich", CreateSandwich_Enter, null, null);
        continueSandwich = _stateMachine.AddActionState("ContinueSandwich", ContinueSandwich_Enter, null, null);
        wrongIngredients = _stateMachine.AddActionState("WrongIngredients", WrongIngredients_Enter, null, null);
        backSandwich = _stateMachine.AddActionState("BackSandwich", BackSandwich_Enter, null, null);
        finishSandwich = _stateMachine.AddActionState("FinishSandwich", FinishSandwich_Enter, null, FinishSandwich_Exit);
        stopPlaying = _stateMachine.AddActionState("StopPlaying", null, null, null);

        _stateMachine.AddTransition(playing, createSandwich, SelectFirstBread);
        _stateMachine.AddTransition(createSandwich, continueSandwich, IsContinueingSandwich);
        _stateMachine.AddTransition(continueSandwich, finishSandwich, IsSandwichFinished);
        _stateMachine.AddTransition(continueSandwich, wrongIngredients, IsWrongIngredients);
        _stateMachine.AddTransition(wrongIngredients, wrongIngredients, IsWrongIngredients);

        _stateMachine.AddTransition(continueSandwich, continueSandwich, IsContinueingSandwich);
        _stateMachine.AddTransition(continueSandwich, backSandwich, IsBackSandwich);
        _stateMachine.AddTransition(backSandwich, continueSandwich, TrueCondition);
        _stateMachine.AddTransition(finishSandwich, backSandwich, IsBackSandwich);
        _stateMachine.AddTransition(finishSandwich, createSandwich, SelectFirstBread);

        _stateMachine.AddTransition(wrongIngredients, backSandwich, IsBackSandwich);
        _stateMachine.AddTransition(wrongIngredients, continueSandwich, TrueCondition);

        _stateMachine.AddTransition(continueSandwich, createSandwich, SelectFirstBread);
        _stateMachine.AddTransition(createSandwich, createSandwich, SelectFirstBread);

        _stateMachine.CurrentState = playing;
    }
开发者ID:nicolas-repiquet,项目名称:FoodTruckSaga,代码行数:32,代码来源:PlayerHuman.cs


注:本文中的StateMachine.AddTransition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。