Ejemplo n.º 1
0
 /// <summary>
 /// Controls ambush behaviour, where a creature tries to sneak up next to another to get a high damage special attack
 /// </summary>
 /// <param name="c"></param>
 public void ambush(Creature c)
 {
     if (isStealthy())
     {
         if (!c.canSee(this))
         {
             if (isAdjacent(c))
             {
                 c.damage((getStrength() / 2) + getStealthVal());
                 spotted();
             }
             else
             {
                 moveTowards(c);
             }
         }
         else
         {
             spotted();
         }
     }
     else
     {
         hide();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Attacks another creature, comparing strength to defence and moving towards the other creature if it is not adjacent
        /// </summary>
        /// <param name="otherCreature">The creature to attack</param>
        public void attack(Creature otherCreature)
        {
            if (isAdjacent(otherCreature))
            {
                int winnerEnergy = 10;
                int loserEnergy = 20;

                otherCreature.attacked(this);
                inCombat = true;
                inCombatWith = otherCreature;
                int attackVal = this.getStrength() + rand(10);
                int defVal = otherCreature.getDefence() + rand(10);

                if (attackVal > defVal)
                {
                    otherCreature.damage(attackVal - defVal);
                    this.drainEnergy(winnerEnergy);
                    otherCreature.drainEnergy(loserEnergy);
                }
                else if (attackVal < defVal)
                {
                    this.damage((defVal - attackVal) / 2);
                    this.drainEnergy(loserEnergy);
                    otherCreature.drainEnergy(winnerEnergy);
                }
                else
                {
                    this.drainEnergy(loserEnergy);
                    otherCreature.drainEnergy(loserEnergy);
                }
            }
            else
            {
                moveTowards(otherCreature);
            }
        }