private void SetDirection(int newPosition) { if (newPosition > currentPosition) { SetDirectionRight(); pigeonAction = PigeonAction.WalkingRight; } else { SetDirectionLeft(); pigeonAction = PigeonAction.WalkingLeft; } }
/// <summary> /// This method is responsible for changing the position of the pigeon. /// </summary> private void ExecuteWalk(int newPosition) { places[newPosition].Pigeon = places[currentPosition].Pigeon; places[currentPosition].Pigeon = null; currentPosition = newPosition; actuator.TriggerChangePigeon(); places[newPosition].Sensor.AddPigeonInPlace(places[newPosition].Pigeon); actuator.TriggerChangePigeon(); Thread.Sleep(Config.pigeonActionDelay); pigeonAction = PigeonAction.Waiting; }
public Pigeon(List <Place> places, int currentPosition) { index = Randomize.GetValue(1, 9); maxTimeWiting = Randomize.GetValue(Config.pigeonMinTimesWaiting, Config.pigeonMaxTimesWaiting); ChoseDirection(); pigeonAction = PigeonAction.Waiting; actuator = new PigeonActuator(); sensor = new PigeonSensor(this); this.places = places; this.currentPosition = currentPosition; thread = new Thread(new ThreadStart(Loop)); thread.Start(); }
/// <summary> /// This method is responsible for performing the act of eating the pigeon. /// Note that eating the food requires interacting with the environment and with the food. /// This interaction is not done here, but delegated through the actuator. /// In other words, the Food and Environment classes that listen to the pigeon thread will know when it ate and perform the appropriate action. /// </summary> private void EatFood(int newPosition) { String currentDirection = ImagePath; if (ImagePath.Contains("left")) { ImagePath = String.Format("Assets\\pigeon{0}_left_nham.png", index); } else { ImagePath = String.Format("Assets\\pigeon{0}_right_nham.png", index); } actuator.TriggerEatPigeon(newPosition); actuator.TriggerChangePigeon(); Thread.Sleep(Config.pigeonActionDelay); ImagePath = currentDirection; actuator.TriggerChangePigeon(); pigeonAction = PigeonAction.Waiting; }