Ejemplo n.º 1
0
        public override void Move(FarmingAction farmAction)
        {
            // Get user to move
            AMovingItem userToMove;

            this.listUsers.TryGetValue(farmAction.With, out userToMove);

            if (userToMove != null)
            {
                // Goat : river to boat
                var action = new ActionDetail(
                    (a, b) => a.MoveTo(b),
                    new FarmingAction
                {
                    To        = farmAction.To,
                    Direction = farmAction.Direction,
                    With      = farmAction.With
                }
                    );
                userToMove.ActionToDo = action;
                action.EndEvent.WaitOne();
            }
            this.PurgeWaitingList();

            // Farmer : river to boat
            this.MoveTo(new FarmingAction
            {
                To        = farmAction.To,
                Direction = farmAction.Direction,
                With      = farmAction.With
            });
            this.PurgeWaitingList();

            // Farmer : boat to river
            this.MoveTo(new FarmingAction
            {
                To        = farmAction.To,
                Direction = farmAction.Direction,
                With      = farmAction.With
            });
            this.PurgeWaitingList();

            if (userToMove != null)
            {
                // Goat : river to boat
                var action = new ActionDetail(
                    (a, b) => a.MoveTo(b),
                    new FarmingAction
                {
                    To        = farmAction.To,
                    Direction = farmAction.Direction,
                    With      = farmAction.With
                }
                    );
                userToMove.ActionToDo = action;
                action.EndEvent.WaitOne();
            }
            this.PurgeWaitingList();
        }
Ejemplo n.º 2
0
        // Constructor
        public ActionDetail(Action <AMovingItem, FarmingAction> function, FarmingAction parameters)
        {
            this.N = ++number;

            // The action to execute
            this.FunctionToCall = function;
            this.Parameters     = parameters;

            // Events
            this.EndEvent = new ManualResetEvent(false);
        }
Ejemplo n.º 3
0
        public void MoveTo(FarmingAction action)
        {
            Direction direction = action.Direction;

            string positionDirection = this.currentPosition.ToString() + direction.ToString();

            if (movingActions.ContainsKey(positionDirection))
            {
                this.currentPosition = movingActions[positionDirection];
            }
            else
            {
                throw new ArgumentException("Direction not available");
            }
        }
Ejemplo n.º 4
0
        public void TryEat(FarmingAction farmingAction)
        {
            EatAction action         = (EatAction)farmingAction;
            Position  farmerPosition = action.FarmerPosition;

            foreach (var myPrey in this.listPrey)
            {
                var preyPosition = myPrey.CurrentPosition;

                if (this.currentPosition != preyPosition)
                {
                    // can't eat !
                }
                else if (this.CurrentPosition != farmerPosition)
                {
                    // can't eat again
                }
                else
                {
                    Console.WriteLine(this.Id.ToString() + " Miammmmmmmmmmmmmmmmmmmmm !");
                    Console.WriteLine("Je mange ma proie");
                }
            }
        }
Ejemplo n.º 5
0
 public virtual void Move(FarmingAction o)
 {
     throw new NotImplementedException();
 }