Пример #1
0
        public AMovingItem GetUser(Farming userId)
        {
            AMovingItem outValue = null;

            this.listUsers.TryGetValue(userId, out outValue);

            return(outValue);
        }
Пример #2
0
        private AMovingItem MyFactory(Farming userId)
        {
            AMovingItem returnValue = null;

            if (userId == Farming.Farmer)
            {
                returnValue = new Farmer(this.listUsers);
            }
            else if (actions.ContainsKey(userId))
            {
                returnValue = actions[userId]();
            }

            return(returnValue);
        }
Пример #3
0
        public void Run()
        {
            // start all threads
            this.StartThreads();
            Thread.Sleep(500);
            Console.WriteLine();

            // Get the list of actions to perform
            var parameters = Orchestrator.GetAction();

            // Run each action
            foreach (var parameter in parameters)
            {
                AMovingItem with;
                this.listUsers.TryGetValue(parameter.With, out with);

                Console.WriteLine("Processing action to {0}, with {1}",
                                  this.listUsers[parameter.To], with);

                // Creation de l'action
                AMovingItem user = null;
                if (this.listUsers.TryGetValue(parameter.To, out user))
                {
                    ActionDetail action = new ActionDetail(
                        (a, b) => a.Move(b),
                        parameter
                        );

                    // Set the action to run
                    user.ActionToDo = action;

                    // Wait for the action to end
                    action.EndEvent.WaitOne();
                }
                else
                {
                    Console.WriteLine("Unknown user !");
                }

                Console.WriteLine();
            }

            // end all threads
            this.EndThreads();
        }
Пример #4
0
 public void AddPrey(AMovingItem prey)
 {
     this.listPrey.AddLast(prey);
 }