public override bool OnMesssage(Sheriff sheriff, Telegram telegram) { switch (telegram.messageType) { case MessageType.Gunfight: // Notify the undertaker Message.DispatchMessage(0, sheriff.Id, Agent.AgentsCount - 1, MessageType.Gunfight); // Gunfight Outlaw outlaw = (AgentManager.GetAgent(telegram.Sender) as Outlaw); if (rand.Next(10) == 1) // sheriff dies { outlaw.GoldCarrying += sheriff.GoldCarrying; sheriff.GoldCarrying = 0; Message.DispatchMessage(0, sheriff.Id, sheriff.Id, MessageType.Dead); } else // outlaw dies { Printer.Print(sheriff.Id, "I am not coward, but I am so strong. It is hard to die."); sheriff.GoldCarrying += outlaw.GoldCarrying; outlaw.GoldCarrying = 0; Message.DispatchMessage(0, sheriff.Id, outlaw.Id, MessageType.Dead); sheriff.StateMachine.ChangeState(new SheriffTravelToTarget(Location.bank, new StopByBankAndDepositGold())); } sheriff.OutlawSpotted = false; return(true); case MessageType.Dead: sheriff.StateMachine.ChangeState(new DropDeadSheriff()); return(true); case MessageType.Respawn: sheriff.StateMachine.ChangeState(new PatrolRandomLocation()); return(true); default: return(false); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Here's a little hack: The Miner and MinersWife must know each other's id in // order to communicate. We calculate them inside each agent based on their // creation order, so the pair must always be created in this sequence. Map = new TileMap(); Bob = new Miner(); Elsa = new MinersWife(); Jesse = new Outlaw(); Wyatt = new Sheriff(); Ripp = new Undertaker(); AgentManager.AddAgent(Bob); AgentManager.AddAgent(Elsa); AgentManager.AddAgent(Jesse); AgentManager.AddAgent(Wyatt); AgentManager.AddAgent(Ripp); // TODO: We could add more agents here base.Initialize(); }