Пример #1
0
        public override int Execute(Miner entity)
        {
            // try to put miner into drinking state
            int result = RND.Roll(100);

            if (result >= 80)
            {
                entity.StateMachine.State = entity.StateMachine.DrinkFromMagicFlask;
            }
            return(0);
        }
Пример #2
0
 public override int Execute(Miner entity)
 {
     // every action makes miner thirsty and more exhausted
     entity.Thirst++;
     entity.Fatigue++;
     Console.WriteLine($"{entity.Name}: in vigorous state");
     if (entity.Fatigued() && entity.Thirsty())
     {
         entity.StateMachine.State = entity.StateMachine.Tired;
     }
     return(RND.Roll(100));
 }
Пример #3
0
        static void Main(string[] args)
        {
            Miner bob = new Miner()
            {
                Name               = "Bob", Location = LocationType.shack1, Home = LocationType.shack1,
                Capacity           = 10, ComfortLevel = 20,
                TirednessThreshold = 10, ThirstLevel = 12
            };
            Miner jim = new Miner()
            {
                Name               = "Jim", Location = LocationType.shack2, Home = LocationType.shack2,
                Capacity           = 4, ComfortLevel = 25,
                TirednessThreshold = 15, ThirstLevel = 15
            };

            // connect them directly, simplistic solution
            bob.Rival = jim;

            for (int i = 0; i < 200; i++)
            {
                // provoke monster invasion
                if (RND.Roll(100) >= 80)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Invasion is coming.");
                    Console.ResetColor();
                    MessageBroker.Instance.Dispatch(new Telegram
                    {
                        Delay    = 0,
                        Message  = (int)Messages.Invasion,
                        Receiver = bob,
                        Sender   = null
                    });
                    MessageBroker.Instance.Dispatch(new Telegram
                    {
                        Delay    = 0,
                        Message  = (int)Messages.Invasion,
                        Receiver = jim,
                        Sender   = null
                    });
                }
                bob.Update();
                jim.Update();
                MessageBroker.Instance.DispatchDelayedMessages();
                Thread.Sleep(100);
                Console.WriteLine();
            }
            bob.Print();
            Console.WriteLine("---------");
            jim.Print();
        }
Пример #4
0
 public override int Execute(Miner entity)
 {
     // every action makes miner double thirsty and more exhausted
     entity.Thirst++;
     entity.Thirst++;
     entity.Fatigue++;
     Console.WriteLine($"{entity.Name}: in tired state");
     if (!entity.Fatigued() || !entity.Thirsty())
     {
         entity.StateMachine.State = entity.StateMachine.Vigorous;
     }
     // can do much less when tired
     return(RND.Roll(70));
 }