コード例 #1
0
        public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram)
        {
            MinersWife wife = (MinersWife)pEntity;

            switch (pTelegram.Msg)
            {
            case (int)message_type.Msg_StewReady:
            {
                DebugMessages.Instance.WriteLine(String.Format("Message received by {0} at time {1}", MainSM.GetEntityName(pEntity.ID()), MessageDispatcher.Instance.GetRunningTime()));
                DebugMessages.Instance.WriteLine(String.Format("{0}: StewReady! Lets eat", MainSM.GetEntityName(pEntity.ID())));

                //let hubby know the stew is ready
                MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY,
                                                           wife.ID(),
                                                           (int)EntityName.ent_Miner_Bob,
                                                           (int)message_type.Msg_StewReady,
                                                           (int)MessageDispatcher.NO_ADDITIONAL_INFO);

                wife.Cooking = false;
                wife.GetFSM().ChangeState(new DoHouseWork());

                return(true);
            }
            }//end switch

            return(false);
        }
コード例 #2
0
ファイル: frmMinerDemo.cs プロジェクト: Cloverseer/thinksharp
        public frmMinerDemo()
        {
            InitializeComponent();

            mHighResTimer = new HighResTimer();

            // m_AsyncWorker will be used to perform the AI work on a background thread.
            m_AsyncWorker = new BackgroundWorker();
            m_AsyncWorker.WorkerReportsProgress = true;
            m_AsyncWorker.ProgressChanged += new ProgressChangedEventHandler(Thread_ProgressChanged);
            m_AsyncWorker.DoWork += new DoWorkEventHandler(Thread_DoWork);
            m_AsyncWorker.WorkerSupportsCancellation = true;

            // Just direct all debug output to our Message Writer
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new TextWriterTraceListener(DebugMessages.Instance));

            groupBox1.ForeColor = mColourBob;
            groupBox2.ForeColor = mColourElsa;
            groupBox3.ForeColor = mColourBarFly;

            //create a miner
            Bob = new Miner((int)EntityName.ent_Miner_Bob);

            //create his wife
            Elsa = new MinersWife((int)EntityName.ent_Elsa);

            Joe = new BarFlyJoe((int)EntityName.ent_BarFly);

            //register them with the Message Dispatcher
            MessageDispatcher.Instance.RegisterEntity(Bob);
            MessageDispatcher.Instance.RegisterEntity(Elsa);
            MessageDispatcher.Instance.RegisterEntity(Joe);
        }
コード例 #3
0
        public override void Execute(BaseGameEntity pEntity)
        {
            MinersWife wife = (MinersWife)pEntity;

            DebugMessages.Instance.WriteLine(String.Format("{0}: Ahhhhhh! Sweet relief! ", MainSM.GetEntityName(pEntity.ID())));
            wife.GetFSM().RevertToPreviousState();
        }
コード例 #4
0
        public frmMinerDemo()
        {
            InitializeComponent();

            mHighResTimer = new HighResTimer();

            // m_AsyncWorker will be used to perform the AI work on a background thread.
            m_AsyncWorker = new BackgroundWorker();
            m_AsyncWorker.WorkerReportsProgress = true;
            m_AsyncWorker.ProgressChanged      += new ProgressChangedEventHandler(Thread_ProgressChanged);
            m_AsyncWorker.DoWork += new DoWorkEventHandler(Thread_DoWork);
            m_AsyncWorker.WorkerSupportsCancellation = true;

            // Just direct all debug output to our Message Writer
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new TextWriterTraceListener(DebugMessages.Instance));

            groupBox1.ForeColor = mColourBob;
            groupBox2.ForeColor = mColourElsa;
            groupBox3.ForeColor = mColourBarFly;

            //create a miner
            Bob = new Miner((int)EntityName.ent_Miner_Bob);

            //create his wife
            Elsa = new MinersWife((int)EntityName.ent_Elsa);

            Joe = new BarFlyJoe((int)EntityName.ent_BarFly);

            //register them with the Message Dispatcher
            MessageDispatcher.Instance.RegisterEntity(Bob);
            MessageDispatcher.Instance.RegisterEntity(Elsa);
            MessageDispatcher.Instance.RegisterEntity(Joe);
        }
コード例 #5
0
        public override void Execute(BaseGameEntity pEntity)
        {
            MinersWife wife = (MinersWife)pEntity;

            //1 in 10 chance of needing the bathroom (provided she is not already
            //in the bathroom)
            if ((Utils.RandFloat() < 0.1) && !wife.GetFSM().isInState(typeof(VisitBathroom)))
            {
                wife.GetFSM().ChangeState(new VisitBathroom());
            }
        }
コード例 #6
0
        public override void Enter(BaseGameEntity pEntity)
        {
            MinersWife wife = (MinersWife)pEntity;

            //if not already cooking put the stew in the oven
            if (!wife.Cooking)
            {
                DebugMessages.Instance.WriteLine(String.Format("{0}: Putting the stew in the oven", MainSM.GetEntityName(pEntity.ID())));

                //send a delayed message myself so that I know when to take the stew
                //out of the oven
                MessageDispatcher.Instance.DispatchMessage(1.5,                               //time delay
                                                           wife.ID(),                         //sender ID
                                                           wife.ID(),                         //receiver ID
                                                           (int)message_type.Msg_StewReady,   //msg
                                                           (int)MessageDispatcher.NO_ADDITIONAL_INFO);

                wife.Cooking = true;
            }
        }
コード例 #7
0
        public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram)
        {
            MinersWife wife = (MinersWife)pEntity;

            switch (pTelegram.Msg)
            {
            case (int)message_type.Msg_HiHoneyImHome:
            {
                double CurrentTime = MessageDispatcher.Instance.GetRunningTime();

                DebugMessages.Instance.WriteLine(String.Format("Message handled by {0} at time: {1}", MainSM.GetEntityName(wife.ID()), CurrentTime));

                DebugMessages.Instance.WriteLine(String.Format("{0}: Hi honey. Let me make you some of mah fine country stew", MainSM.GetEntityName(wife.ID())));

                wife.GetFSM().ChangeState(new CookStew());

                return(true);
            }
            }

            return(false);
        }