コード例 #1
0
ファイル: Seasons.cs プロジェクト: wakingviolet/FSMsharp
        public void Init()
        {
            // Initialize the states, adding them to the FSM and configuring their behaviour

            fsm.Add(Season.Winter)
            .Expires(3f)
            .GoesTo(Season.Spring)
            .OnEnter(() => Console.ForegroundColor = ConsoleColor.White)
            .OnLeave(() => Console.WriteLine("Winter is ending..."))
            .Calls(d => Console.WriteLine("Winter is going on.. {0}%", d.StateProgress * 100f));

            fsm.Add(Season.Spring)
            .Expires(3f)
            .GoesTo(Season.Summer)
            .OnEnter(() => Console.ForegroundColor = ConsoleColor.Green)
            .OnLeave(() => Console.WriteLine("Spring is ending..."))
            .Calls(d => Console.WriteLine("Spring is going on.. {0}%", d.StateProgress * 100f));

            fsm.Add(Season.Summer)
            .Expires(3f)
            .GoesTo(Season.Fall)
            .OnEnter(() => Console.ForegroundColor = ConsoleColor.Red)
            .OnLeave(() => Console.WriteLine("Summer is ending..."))
            .Calls(d => Console.WriteLine("Summer is going on.. {0}%", d.StateProgress * 100f));

            fsm.Add(Season.Fall)
            .Expires(3f)
            .GoesTo(Season.Winter)
            .OnEnter(() => Console.ForegroundColor = ConsoleColor.DarkYellow)
            .OnLeave(() => Console.WriteLine("Fall is ending..."))
            .Calls(d => Console.WriteLine("Fall is going on.. {0}%", d.StateProgress * 100f));

            // Very important! set the starting state
            fsm.CurrentState = Season.Winter;
        }
コード例 #2
0
 private void InitStates()
 {
     State       = new FSM <EnemyState, BaseEnemyAIState>();
     _idleState  = new EnemyIdleState(this);
     _chaseState = new EnemyChaseState(this);
     State.Add(EnemyState.IDLE, _idleState);
     State.Add(EnemyState.CHASE, _chaseState);
     State.SetState(EnemyState.IDLE);
 }
コード例 #3
0
    // Start is called before the first frame update
    void Start()
    {
        Pieces         = transform.Find("Cube Group");
        piecePositions = GetInitialPositions(Pieces);
        //FINALLY after declaring the state classes
        //create the three states and add them to the fsm
        m_fsm.Add((int)GameStates.SETUP, new Setup(m_fsm, this));
        m_fsm.Add((int)GameStates.PLAY, new Play(m_fsm, this));
        m_fsm.Add((int)GameStates.CLEANUP, new Setup(m_fsm, this, Setup.MoveType.MOVE_OUT));
        //set the states of the fsm

        m_fsm.SetCurrentState(m_fsm.GetState((int)GameStates.SETUP));
    }
コード例 #4
0
    public void Init(LevelData data)
    {
        _data = data;
        InitParameters();

        mode = new FSM <LEVEL_WIN_MODE, LevelMode>();
        mode.Add(LEVEL_WIN_MODE.MAX_SCORE_MODE, new ScoreLevelMode(this));
        mode.Add(LEVEL_WIN_MODE.TIMER_MODE, new TimeLevelMode(this));
        mode.SetState(data.levelMode);

        Hero.onDefeat += OnHeroDefeat;
        EventManager.Get <AddScoreEvent>().Subscribe(OnAddScoreEvent);
    }
コード例 #5
0
        public PlatformModel(PlatformConfig config)
        {
            _config = config;

            fsm = new FSM <PlatformState, BasePlatformState>();

            /*fsm.Add(new UpState(_config.upStateDuration));
             * fsm.Add(new DownState(_config.downStateDuration));*/
            fsm.Add(new BasePlatformState(PlatformState.Up, PlatformState.Down, _config.upStateDuration));
            fsm.Add(new BasePlatformState(PlatformState.Down, PlatformState.Appear, _config.downStateDuration));
            fsm.Add(new BasePlatformState(PlatformState.Appear, PlatformState.Up, _config.highlightDuration));

            fsm.OnStateChanged += OnStateChanged;
        }
コード例 #6
0
    // Use this for initialization
    void Start()
    {
        brain = new FSM();
        brain.Add(Wander);

        idleTime = -1;
    }
コード例 #7
0
        public XmasLogBehaviour1(Boss boss) : base(boss)
        {
            // State machine
            _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour1");

            var targetingInitialPositionBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition)
                .OnUpdate(TargetingInitialPositionTaskUpdate);

            var shootingPatternBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.ShootingPattern)
                .OnEnter(ShootingPatternTaskEnter);

            _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour);
            _stateMachine.Add(BehaviourState.ShootingPattern, shootingPatternBehaviour);
        }
コード例 #8
0
        public XmasSnowmanBehaviour4(Boss boss) : base(boss)
        {
            // State machine
            _stateMachine = new FSM <BehaviourState>("xmas-snowman-behaviour4");

            var targetingInitialPositionBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition)
                .OnUpdate(TargetingInitialPositionTaskUpdate);

            var hatAttackBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.HatAttack)
                .OnEnter(HatAttackTaskEnter)
                .OnUpdate(HatAttackTaskUpdate);

            _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour);
            _stateMachine.Add(BehaviourState.HatAttack, hatAttackBehaviour);
        }
コード例 #9
0
        public XmasLogBehaviour2(Boss boss) : base(boss)
        {
            // State machine
            _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour2");

            var targetingScreenCenterBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.TargetingScreenCenter)
                .OnUpdate(TargetingScreenCenterTaskUpdate);

            var shootingPatternBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.HelicopterPattern)
                .OnEnter(HelicopterPatternTaskEnter)
                .OnUpdate(HelicopterPatternTaskUpdate);

            _stateMachine.Add(BehaviourState.TargetingScreenCenter, targetingScreenCenterBehaviour);
            _stateMachine.Add(BehaviourState.HelicopterPattern, shootingPatternBehaviour);
        }
コード例 #10
0
        public XmasSnowmanBehaviour3(Boss boss) : base(boss)
        {
            // State machine
            _stateMachine = new FSM <BehaviourState>("xmas-snowman-behaviour3");

            var targetingInitialPositionBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition)
                .OnUpdate(TargetingInitialPositionTaskUpdate);

            var carrotShotBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.CarrotShot)
                .OnEnter(CarrotShotTaskEnter)
                .OnUpdate(CarrotShotTaskUpdate);

            _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour);
            _stateMachine.Add(BehaviourState.CarrotShot, carrotShotBehaviour);
        }
コード例 #11
0
ファイル: SwipeMove.cs プロジェクト: robin84bobin/SpaceArcade
    private void InitStates()
    {
        State = new FSM <SwipeState, SwipeAbstractState>();

        _idleState = new SwipeIdleState(this);

        _touchedState = new SwipeTouchedState(this);
        _touchedState.moveThreshold  = moveThreshold;
        _touchedState.swipeThreshold = swipeThreshold;
        _touchedState.straightness   = straightness;

        _untouchedState = new SwipeUntouchedState(this);
        _untouchedState.moveThreshold = moveThreshold;
        _untouchedState.straightness  = straightness;

        State.Add(SwipeState.IDLE, _idleState);
        State.Add(SwipeState.TOUCHED, _touchedState);
        State.Add(SwipeState.UNTOUCHED, _untouchedState);
    }
コード例 #12
0
        public XmasLogBehaviour3(Boss boss) : base(boss)
        {
            // State machine
            _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour3");

            var targetingInitialPositionBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition)
                .OnUpdate(TargetingInitialPositionTaskUpdate);

            var babyLogBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.BabyLogs)
                .OnEnter(BabyLogTaskEnter)
                .OnUpdate(BabyLogTaskUpdate);

            _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour);
            _stateMachine.Add(BehaviourState.BabyLogs, babyLogBehaviour);

            _babyLogs = new List <BabyLog>();
        }
コード例 #13
0
    public void Idle()
    {
        if (idleTime == -1)
        {
            idleTime = Random.Range(5.0f, 25.0f);
        }

        // Play Idle animation

        if (brain.timer > idleTime)
        {
            idleTime = -1;
            brain.Pop();
            brain.Add(Wander);
        }
        if (CanPlayerBeSeen())
        {
            idleTime = -1;
            brain.Add(Chase);
        }
    }
コード例 #14
0
        public XmasLogBehaviour4(Boss boss) : base(boss)
        {
            // State machine
            _stateMachine = new FSM <BehaviourState>("xmas-log-behaviour4");

            var targetingInitialPositionBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition)
                .OnUpdate(TargetingInitialPositionTaskUpdate);

            var removingHollyBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.HollyAttack)
                .OnEnter(RemovingHollyTaskEnter);

            var hollyAttackBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.HollyAttack)
                .OnEnter(HollyAttackTaskEnter)
                .OnUpdate(HollyAttackTaskUpdate);

            _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour);
            _stateMachine.Add(BehaviourState.RemovingHolly, removingHollyBehaviour);
            _stateMachine.Add(BehaviourState.HollyAttack, hollyAttackBehaviour);
        }
コード例 #15
0
        public void SnapshotRestore()
        {
            FSM <int> F = new FSM <int>("");

            F.Add(1)
            .Expires(5)
            .GoesTo(2);
            F.Add(2);

            F.CurrentState = 1;

            F.Process(0f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(1f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(2f);
            Assert.AreEqual(1, F.CurrentState);

            var snap = F.SaveSnapshot();

            F.Process(3f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(4f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(5.1f);
            Assert.AreEqual(2, F.CurrentState);

            F.RestoreSnapshot(snap);
            Assert.AreEqual(1, F.CurrentState);

            F.Process(3f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(4f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(5.1f);
            Assert.AreEqual(2, F.CurrentState);
        }
コード例 #16
0
        public void OnEnterAndOnLeaveHandlers()
        {
            FSM <int>          F = new FSM <int>("");
            RefContainer <int> x = new RefContainer <int>();

            F.Add(1)
            .Expires(5)
            .GoesTo(2)
            .OnLeave(() => x.Value += 15);
            F.Add(2)
            .OnEnter(() => x.Value *= 2);

            F.CurrentState = 1;
            F.Process(0f);

            F.Process(5.1f);
            Assert.AreEqual(30, x.Value);
            F.Process(5.2f);
            Assert.AreEqual(30, x.Value);
            F.Process(5.3f);
            Assert.AreEqual(30, x.Value);
            F.Process(5.4f);
            Assert.AreEqual(30, x.Value);
        }
コード例 #17
0
        public void StateIsLeavedImmediatelyOnSuddenExpiration()
        {
            FSM <int>          F = new FSM <int>("");
            RefContainer <int> x = new RefContainer <int>();

            F.Add(1)
            .Expires(1)
            .GoesTo(2);
            F.Add(2)
            .GoesTo(3)
            .Expires(1)
            .OnLeave(() => x.Value += 15);
            F.Add(3)
            .OnEnter(() => x.Value *= 2);

            F.CurrentState = 1;
            F.Process(0f);

            F.Process(1.5f);
            F.Process(3f);

            Assert.AreEqual(3, F.CurrentState);
            Assert.AreEqual(30, x.Value);
        }
コード例 #18
0
        public void SimpleExpiration()
        {
            FSM <int> F = new FSM <int>("");

            F.Add(1)
            .Expires(5)
            .GoesTo(2);
            F.Add(2);

            F.CurrentState = 1;

            F.Process(0f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(1f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(2f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(3f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(4f);
            Assert.AreEqual(1, F.CurrentState);
            F.Process(5.1f);
            Assert.AreEqual(2, F.CurrentState);
        }
コード例 #19
0
        public XmasSnowmanBehaviour1(Boss boss) : base(boss)
        {
            InitialBehaviourLife = GameConfig.BossDefaultBehaviourLife * 0.5f;

            // State machine
            _stateMachine = new FSM <BehaviourState>("xmas-snowman-behaviour1");

            var targetingInitialPositionBehaviour =
                new FSMBehaviour <BehaviourState>(BehaviourState.TargetingInitialPosition)
                .OnEnter(TargetingInitialPositionTaskEnter)
                .OnUpdate(TargetingInitialPositionTaskUpdate)
                .OnExit(TargetingInitialPositionTaskExit);

            _stateMachine.Add(BehaviourState.TargetingInitialPosition, targetingInitialPositionBehaviour);

            _initialBehaviourPosition = new Vector2(Boss.InitialPosition.X, Boss.InitialPosition.Y + 500);
        }
コード例 #20
0
 public void Start()
 {
     m_StartWait = new WaitForSeconds(m_StartDelay);
     m_EndWait   = new WaitForSeconds(m_EndDelay);
     m_Tanks     = new List <GameObject>();
     GameStart   = false;
     m_Fsm.Add((int)GameManagerStateEnum.DISCONNECT, new DisconnectState(m_Fsm, this));
     m_Fsm.Add((int)GameManagerStateEnum.WAITING_PLAYER, new WaitingPlayerState(m_Fsm, this));
     m_Fsm.Add((int)GameManagerStateEnum.NOT_READY, new NotReadyState(m_Fsm, this));
     m_Fsm.Add((int)GameManagerStateEnum.WAITING_ALL_READY, new WaitingAllReadyState(m_Fsm, this));
     m_Fsm.Add((int)GameManagerStateEnum.PLAYING, new PlayingState(m_Fsm, this));
     m_Fsm.Add((int)GameManagerStateEnum.FINISH_PLAY, new FinishPlayState(m_Fsm, this));
     m_Fsm.SetCurrentState(m_Fsm.GetState((int)GameManagerStateEnum.DISCONNECT));
 }
コード例 #21
0
        private static void Main(string[] args)
        {
            fsm = new FSM <char>("start");

            fsm.Add("start", '+', null, "whole");
            fsm.Add("start", '-', c => fsm.Variables.sign = -1, "whole");
            fsm.Add("start", char.IsDigit, AddChar, "whole");
            fsm.Add("start", '.', c => fsm.Variables.divisor = 0.1, "fract");

            fsm.Add("whole", char.IsDigit, AddChar);
            fsm.Add("whole", '.', c => fsm.Variables.divisor = 0.1, "fract");

            fsm.Add("fract", char.IsDigit, c =>
            {
                fsm.Variables.number  += fsm.Variables.divisor * (c - '0');
                fsm.Variables.divisor /= 10;
            });

            fsm.OnStart = () =>
            {
                fsm.Variables.sign    = 1;
                fsm.Variables.number  = 0.0;
                fsm.Variables.divisor = 0.0;
            };

            Verify();

            do
            {
                Console.Write("Enter a number: ");
                var s = Console.ReadLine();
                if (string.IsNullOrEmpty(s))
                {
                    break;
                }

                fsm.Restart();
                foreach (var c in s)
                {
                    fsm.Handle(c);
                }

                Console.WriteLine("The number is " + fsm.Variables.sign * fsm.Variables.number);
            } while (true);
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: njmube/public
        private static void Main(string[] args)
        {
            fsm = new FSM<char>("start");

              fsm.Add("start", '+', null, "whole");
              fsm.Add("start", '-', c => fsm.Variables.sign = -1, "whole");
              fsm.Add("start", char.IsDigit, AddChar, "whole");
              fsm.Add("start", '.', c => fsm.Variables.divisor = 0.1, "fract");

              fsm.Add("whole", char.IsDigit, AddChar);
              fsm.Add("whole", '.', c => fsm.Variables.divisor = 0.1, "fract");

              fsm.Add("fract", char.IsDigit, c =>
              {
            fsm.Variables.number += fsm.Variables.divisor * (c - '0');
            fsm.Variables.divisor /= 10;
              });

              fsm.OnStart = () =>
              {
            fsm.Variables.sign = 1;
            fsm.Variables.number = 0.0;
            fsm.Variables.divisor = 0.0;
              };

              Verify();

              do
              {
            Console.Write("Enter a number: ");
            var s = Console.ReadLine();
            if (string.IsNullOrEmpty(s))
              break;

            fsm.Restart();
            foreach (var c in s)
              fsm.Handle(c);

            Console.WriteLine("The number is " + fsm.Variables.sign * fsm.Variables.number);
              } while (true);
        }
コード例 #23
0
        private void SetUp()
        {
            fsm.OnStart = () =>
            {
                sign    = 1;
                number  = 0.0;
                divisor = 0.0;
            };

            fsm.Add("start", '+', null, "whole");
            fsm.Add("start", '-', _ => sign = -1, "whole");
            fsm.Add("start", char.IsDigit, AddChar, "whole");
            fsm.Add("start", '.', _ => divisor = 0.1, "fract");

            fsm.Add("whole", char.IsDigit, AddChar);
            fsm.Add("whole", '.', _ => divisor = 0.1, "fract");

            fsm.Add("fract", char.IsDigit, c =>
            {
                number  += divisor * (c - '0');
                divisor /= 10;
            });
        }
コード例 #24
0
 /// <summary>
 /// Queues a new state to specified FSM.
 /// </summary>
 /// <param name="fsm">The FSM.</param>
 /// <returns>The newly created state.</returns>
 public static FsmStateBehaviour <sbyte> Queue(this FSM <sbyte> fsm)
 {
     return(fsm.Add((sbyte)fsm.Count)
            .GoesTo((sbyte)(fsm.Count + 1)));
 }
コード例 #25
0
 /// <summary>
 /// Queues a new state to specified FSM.
 /// </summary>
 /// <param name="fsm">The FSM.</param>
 /// <returns>The newly created state.</returns>
 public static FsmStateBehaviour <ushort> Queue(this FSM <ushort> fsm)
 {
     return(fsm.Add((ushort)fsm.Count)
            .GoesTo((ushort)(fsm.Count)));
 }
コード例 #26
0
 /// <summary>
 /// Queues a new state to specified FSM.
 /// </summary>
 /// <param name="fsm">The FSM.</param>
 /// <returns>The newly created state.</returns>
 public static FsmStateBehaviour <ulong> Queue(this FSM <ulong> fsm)
 {
     return(fsm.Add((ulong)fsm.Count)
            .GoesTo((ulong)(fsm.Count)));
 }
コード例 #27
0
 /// <summary>
 /// Queues a new state to specified FSM.
 /// </summary>
 /// <param name="fsm">The FSM.</param>
 /// <returns>The newly created state.</returns>
 public static FsmStateBehaviour <int> Queue(this FSM <int> fsm)
 {
     return(fsm.Add(fsm.Count)
            .GoesTo(fsm.Count));
 }
コード例 #28
0
 /// <summary>
 /// Queues a new state to specified FSM.
 /// </summary>
 /// <param name="fsm">The FSM.</param>
 /// <returns>The newly created state.</returns>
 public static FsmStateBehaviour <char> Queue(this FSM <char> fsm)
 {
     return(fsm.Add((char)fsm.Count)
            .GoesTo((char)(fsm.Count + 1)));
 }
コード例 #29
0
 public virtual void Register()
 {
     fsm.Add(CharState.IDLE, EnterIdle, RunIdle, ExitIdle);
     fsm.Add(CharState.ATTACK, EnterAttack, RunAttack, ExitAttack);
     fsm.SetState(CharState.IDLE);
 }
コード例 #30
0
ファイル: CFsm.cs プロジェクト: ocdy1001/MonogameCore
 public override void Init()
 {
     fsm.Add("sayhello", Hello);
     fsm.Add("saygoodbye", Doei);
 }
コード例 #31
0
 public BaseSheepModel()
 {
     _fsm = new FSM <SheepState, BaseState <SheepState> >();
     _fsm.Add(new BaseSheepState(SheepState.Death));
     _fsm.OnStateChanged += OnStateChanged;
 }