public abstract class Zombie
{
public int blood = 20;
public int downBlood = 3;
public int beAttack = 0;
public abstract void DownBlood();
public abstract void Dead();
}
public class CommonZombie : Zombie
{
public override void Dead()
{
Console.WriteLine("普通僵尸死了");
}
public override void DownBlood()
{
while (true)
{
blood -= downBlood;
beAttack++;
if (blood <= 0)
{
Dead();
Console.WriteLine("被打了" + beAttack + "次");
break;
}
}
}
}
public class DefenseZombie : Zombie
{
public bool isHaveDefense = true;
public void IsHaveDefense()
{
if (blood >= blood / 2)
{
downBlood = 2;
} else
{
downBlood = 3;
}
}
public override void Dead()
{
Console.WriteLine("路障僵尸死了");
}
public override void DownBlood()
{
while (true)
{
IsHaveDefense();
blood -= downBlood;
beAttack++;
if (blood <= 0)
{
Dead();
Console.WriteLine("被打了" + beAttack + "次");
break;
}
}
}
}
Console.WriteLine("开始测试僵尸:");
CommonZombie commonZombie = new CommonZombie();
DefenseZombie defenseZombie = new DefenseZombie();
commonZombie.DownBlood();
defenseZombie.DownBlood();