Пример #1
0
        public AutomatedCop(CapturableAutomatedRobber robber)
        {
            this.robber = robber;

            myStateMachine = new StateManager <AutomatedCop>(this);

            //build states
            var stakeOutState = new AutomatedCopStakeOutState <AutomatedCop>();
            var offDutyState  = new AutomatedCopOffDutyState <AutomatedCop>();
            var chasingState  = new AutomatedCopChasingState <AutomatedCop>();

            //connect states
            stakeOutState.AddExitState(chasingState);
            stakeOutState.AddExitState(offDutyState);
            offDutyState.AddExitState(stakeOutState);
            chasingState.AddExitState(stakeOutState);
            chasingState.AddExitState(offDutyState);

            //add states too stateMachine
            myStateMachine.AddState(stakeOutState, true);
            myStateMachine.AddState(offDutyState);
            myStateMachine.AddState(chasingState);

            try
            {
                if (!myStateMachine.EnableStateMachine())
                {
                    Console.WriteLine("State machine failed to enalbe");
                }
            }
            catch (StateNotIncludedException e)
            {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
            }
        }
Пример #2
0
        public override int run()
        {
            var robber = new CapturableAutomatedRobber();
            var cop    = new AutomatedCop(robber);

            while (!robber._isCaptured)
            {
                Console.Write("robberBlerb :");
                robber.EvaluateStateMachine();
                Console.Write("copBlerb :");
                cop.EvaluateStateMachine();
                Console.WriteLine();
                System.Threading.Thread.Sleep(500);
            }
            return(base.run());
        }