The ShelledLifelet class represents a protected Lifelet which is only accessable for one specific simulation step. This creates an overhead but ensures that people can't cheat by storing handles to all the lifelets they come across...
Пример #1
0
 public Lifelet UnshellLifelet(ShelledLifelet shelled)
 {
     //TODO: This is not very efficient... Should we re-write LoopList as a Hashtable?
     foreach(Lifelet lifelet in _lifelets) {
         if(shelled.UID == lifelet.UID) return lifelet;
     }
     return null;
 }
 public double Distance(ShelledLifelet other)
 {
     checkIfValid();
     return _lifelet.Distance(other);
 }
Пример #3
0
        /// <summary>
        /// Attacks another lifelet with the given amount of energy.
        /// </summary>
        protected void attack(ShelledLifelet other, double amount)
        {
            // Check delay
            if(!this.CanAttack) return;

            // Make sure we have this energy to give and we are in distance
            if(this.Energy >= amount && this.Distance(other) < Config.LifeletMaximumAttackRange) {
                _energy -= amount;
                _world.UnshellLifelet(other).recieveAttack(this,amount);
            }
        }
Пример #4
0
        /// <summary>
        /// Gives a specific amount of energy to another lifelet.
        /// </summary>
        protected void giveEnergy(ShelledLifelet other, double amount)
        {
            // Check delay
            if(!this.CanGiveEnergy) return;

            // Make sure we have this energy to give and we are in distance
            if(this.Energy >= amount && this.Distance(other) < this.Visibility) {
                _energy -= amount;
                _world.UnshellLifelet(other).recieveEnergy(this,amount);
            }
        }
Пример #5
0
 /// <summary>
 /// Measures the distance from this lifelet to another.
 /// </summary>
 public double Distance(ShelledLifelet other)
 {
     return this.Position.Distance(other.Position);
 }