Example #1
0
 // Attempt to send a message to a particular agent; called by the preceding two methods -- don't call this from your own agents
 public static void SendMessage(Agent agent, Telegram telegram)
 {
     if (!agent.HandleMessage(telegram))
     {
         Printer.PrintMessageData("Message not handled");
     }
 }
Example #2
0
        public override bool OnMesssage(Miner miner, Telegram telegram)
        {
            switch (telegram.messageType)
            {
            case MessageType.HiHoneyImHome:
                return(false);

            case MessageType.StewsReady:
                Printer.PrintMessageData("Message handled by " + miner.Id + " at time ");
                Printer.Print(miner.Id, "Okay Hun, ahm a comin'!");
                miner.StateMachine.ChangeState(new EatStew());
                return(true);

            default:
                return(false);
            }
        }
Example #3
0
        // This message is used by agents to dispatch messages to other agents -- use this from your own agents
        public static void DispatchMessage(double delay, int sender, int receiver, MessageType messageType)
        {
            Agent sendingAgent   = AgentManager.GetAgent(sender);
            Agent receivingAgent = AgentManager.GetAgent(receiver);

            Telegram telegram = new Telegram(0, sender, receiver, messageType);

            if (delay <= 0.0f)
            {
                Printer.PrintMessageData("Instant telegram dispatched by " + sender + " for " + receiver + " message is " + MessageToString(messageType));
                SendMessage(receivingAgent, telegram);
            }
            else
            {
                telegram.DispatchTime = (int)gameTime.TotalGameTime.Ticks + delay;
                telegramQueue.Add(telegram);
                Printer.PrintMessageData("Delayed telegram from " + sender + " recorded at time " + gameTime.TotalGameTime.Ticks);
            }
        }
Example #4
0
        public override bool OnMesssage(MinersWife minersWife, Telegram telegram)
        {
            switch (telegram.messageType)
            {
            case MessageType.HiHoneyImHome:
                // Ignored here; handled in WifesGlobalState below
                return(false);

            case MessageType.StewsReady:
                // Tell Miner that the stew is ready now by sending a message with no delay
                Printer.PrintMessageData("Message handled by " + minersWife.Id + " at time ");
                Printer.Print(minersWife.Id, "StewReady! Lets eat");
                Message.DispatchMessage(0, minersWife.Id, minersWife.HusbandId, MessageType.StewsReady);
                minersWife.Cooking = false;
                minersWife.StateMachine.ChangeState(new DoHouseWork());
                return(true);

            default:
                return(false);
            }
        }
Example #5
0
        public override bool OnMesssage(MinersWife minersWife, Telegram telegram)
        {
            switch (telegram.messageType)
            {
            case MessageType.HiHoneyImHome:
                Printer.PrintMessageData("Message handled by " + minersWife.Id + " at time ");
                Printer.Print(minersWife.Id, "Hi honey. Let me make you some of mah fine country stew");
                minersWife.StateMachine.ChangeState(new CookStew());
                return(true);

            case MessageType.StewsReady:
                return(false);

            case MessageType.SheriffEncountered:
                //Printer.PrintMessageData("Message handled by " + minersWife.Id + " at time ");
                Printer.Print(minersWife.Id, "Good day to you too, sir!");
                return(true);

            default:
                return(false);
            }
        }