コード例 #1
0
 public void attack(object obj)
 {
     if (obj is Humans)
     {
         Humans trg = obj as Humans;
         System.Console.WriteLine(this.Name + " attacks " + trg.Name + "!");
         int dmg = 5 * this.Strength;
         trg.Health -= dmg;
         System.Console.WriteLine(trg.Name + " was hit for " + dmg + " hp! They have " + trg.Health + " remaining");
     }
     else
     {
         System.Console.WriteLine("you can't attack that, doofus");
     }
 }
コード例 #2
0
 public void fireball(object obj)
 {
     if (obj is Humans)
     {
         Humans trg = obj as Humans;
         System.Console.WriteLine(this.Name + " attacks " + trg.Name + "!");
         Random rand = new Random();
         int    dmg  = rand.Next(20, 51);
         trg.Health -= dmg;
         System.Console.WriteLine(trg.Name + " was blasted for " + dmg + " hp! They have " + trg.Health + " remaining");
     }
     else
     {
         System.Console.WriteLine("Woops! Looks like " + this.Name + "'s old age is catching up with him again... he's attacking things at random!");
     }
 }
コード例 #3
0
 public void death_blow(object obj)
 {
     if (obj is Humans)
     {
         Humans trg = obj as Humans;
         if (trg.Health < 50)
         {
             System.Console.WriteLine($"{this.Name} feels the weakness in {trg.Name}, and makes the Death Blow.");
             System.Console.WriteLine($"{trg.Name} is struck for {trg.Health} hp, and keels over ded!");
             trg.Health = 0;
         }
         else
         {
             System.Console.WriteLine($"{trg.Name} is still too strong for a Death Blow, so {this.Name} attacks instead.");
             attack(trg);
         }
     }
 }