///// <summary> ///// Gets the color of the draw. ///// </summary> ///// <value> ///// The color of the draw. ///// </value> // public override Color DrawColor // { // get // { // return this.Settings.FishColor; // } // } /// <summary> /// Steps of fish. /// </summary> public override void Step() { // increase lifetime this.Lifetime++; if (this.BreedMoveStep()) { WatorSimulation.ChangeFishPopulation(true); } // set step down - animal moved this.IsMoved = true; }
/// <summary> /// Steps of shark. /// </summary> public override void Step() { bool lockTaken = false; // increase lifetime this.Lifetime++; // find fish around var preyFieldDirection = this.GetRandomFishDirectionAround(); var preyField = this.GetFieldFromDirection(preyFieldDirection); // shark eats a fish if found if (preyField != null) { try { if (this.CheckLockRequired(preyFieldDirection, preyField)) { Monitor.Enter(preyField, ref lockTaken); } // check again fish is on field - could be changed in meantime if (preyField.Animal != null) { // clear own old animal space this.Field.Animal = null; // fish dies (clear animal.field and field.animal) preyField.Animal.Die(); WatorSimulation.ChangeFishPopulation(false); // fish is dead place shark on field preyField.Animal = this; // set fíeld as new place for shark this.Field = preyField; } } finally { if (lockTaken) { Monitor.Exit(preyField); } } } else { // if no fish found - increase starve this.Starve++; if (this.Starve > this.Settings.SharkStarveTime) { // shark dies (animal.field null and field.animal.null) this.Die(); WatorSimulation.ChangeSharkPopulation(false); return; } } // execute breed and move if (this.BreedMoveStep()) { WatorSimulation.ChangeSharkPopulation(true); } // set step down - animal moved this.IsMoved = true; }