Exemplo n.º 1
0
        public Strength GetStrengthOf(IOtherCritter otherCritter)
        {
            int otherEnergy = ((Critter)otherCritter).Energy;

            if (otherEnergy == energy)
            {
                return(Strength.Equal);
            }
            else if (otherEnergy < energy)
            {
                if (otherEnergy + 20 < energy)
                {
                    return(Strength.MuchWeaker);
                }
                else
                {
                    return(Strength.Weaker);
                }
            }
            else
            {
                if (otherEnergy > energy + 20)
                {
                    return(Strength.MuchStronger);
                }
                else
                {
                    return(Strength.Stronger);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Attack a given critter.
 /// </summary>
 /// <param name="otherCritter">Reference to other critter.</param>
 /// <returns>Result of attack.</returns>
 public EnumAttackResult Attack(IOtherCritter otherCritter)
 {
     return(_body.Attack(otherCritter));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Get the strength of a given critter.
 /// </summary>
 /// <param name="otherCritter">Reference to other critter.</param>
 /// <returns>Strength</returns>
 public Strength GetStrengthOf(IOtherCritter otherCritter)
 {
     return(_body.GetStrengthOf(otherCritter));
 }
Exemplo n.º 4
0
 private bool IsTouching(IOtherCritter otherCritter)
 {
     return(IsTouching(otherCritter.X, otherCritter.Y, otherCritter.BoundingRadius, CritterBoundingRadius));
 }
Exemplo n.º 5
0
        public EnumAttackResult Attack(IOtherCritter otherCritter)
        {
            if (IsDead)
            {
                return(EnumAttackResult.IAmDead);
            }
            Critter other = (Critter)otherCritter;

            if (other.IsDead)
            {
                return(EnumAttackResult.DeadAlready);
            }
            if (!IsTouching(otherCritter))
            {
                return(EnumAttackResult.TooFarAway);
            }
            bool iWin = false;

            if (other.Energy == energy)
            {
                // The two are evenly matched, so the result is 50/50
                iWin = Utility.NextRandom(0, 2) == 0;
            }
            else if (other.Energy < energy)
            {
                // The other critter is weaker
                if (other.Energy + 20 < energy)
                {
                    // 90% of me winning
                    iWin = Utility.NextRandom(0, 10) > 0;
                }
                else
                {
                    // 75% of me winning
                    iWin = Utility.NextRandom(0, 100) > 24;
                }
            }
            else
            {
                if (other.Energy > energy + 20)
                {
                    // 10% of me winning
                    iWin = Utility.NextRandom(0, 10) == 0;
                }
                else
                {
                    // 25% of me winning
                    iWin = Utility.NextRandom(0, 100) < 25;
                }
            }
            int energyLoss = Utility.NextRandom(5, 11);

            if (iWin)
            {
                // We win
                Energy = Energy - energyLoss > 5 ? Energy - energyLoss : 5;
                string msg = WhoAmI + " attacked and killed " + other.WhoAmI + ".";
                Logger.OutputToLog(msg, Logger.LogLevel.Message);
                CritterWorldForm.AddMarqueeMessage(msg, Color.DarkRed);
                other.Die("Killed by " + WhoAmI);
                return(EnumAttackResult.Killed);
            }
            else
            {
                // They win
                other.Energy = other.Energy - energyLoss > 5 ? other.Energy - energyLoss : 5;
                string msg = WhoAmI + " attacked and was killed by " + other.WhoAmI + ".";
                Logger.OutputToLog(msg, Logger.LogLevel.Message);
                CritterWorldForm.AddMarqueeMessage(msg, Color.DarkRed);
                Die("Killed by " + other.WhoAmI);
                return(EnumAttackResult.IDied);
            }
        }
Exemplo n.º 6
0
 public OtherCritter(IOtherCritter otherCritter, ICritter me)
 {
     _otherCritter = otherCritter;
     _me           = me;
 }