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(); }
// 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); }
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"); } }
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"); } } }
public virtual void Move(FarmingAction o) { throw new NotImplementedException(); }