public override bool feed(Morg predator, Morg prey) { int distance = predator.distance(prey); if (distance == 0) { if (predator.preyTypes.Contains(prey.type)) { prey.kill (); predator.life += prey.life / 2; } } return distance == 0; }
/** Copy constructor */ public Morg(Morg m) { this._color = m.color; this._name = m.name; this._type = m.type; this._alive = m.alive; this._life = m.life; this._preyTypes = m._preyTypes; this.position = m.position; this.target = m.target; this.prey = m.prey; this.observers = m.observers; }
public abstract bool feed(Morg predator, Morg prey);
/** Called when an observed prey is updated */ private void notify(Morg prey) { this.target = prey.position; }
/** Unregister an observer of this morg */ public void unregisterObserver(Morg observer) { this.observers.Remove(observer); }
/** Register an observer to observe this morg. The observer will be notified whenever this morg's notifyAll() method is called */ public void registerObserver(Morg observer) { this.observers.Add(observer); }
public int distance(Morg prey) { return distanceStrategy.distance(this.position, prey.position); }