狼和狮子的简单游戏。
class Program
{
static void Main(string[] args)
{
Lion lion = new Lion();
Wolf[] wolves = new Wolf[9];
for (int i = 0; i < wolves.Length; i++)
{
wolves[i] = new Wolf();
}
Console.WriteLine("我们现在共有{0}只狼",Wolf.WolvesCount);
for (int i = 0; i < wolves.Length; i++)
{
Console.Write("wof{0}", i+1);
wolves[i].Act();
}
lion.CounerAttack();
Console.ReadKey();
}
}
class Wolf
{
public static int WolvesCount = 0;
public Wolf()
{
WolvesCount++;
}
~Wolf()
{
WolvesCount--;
}
public void Act()
{
if (WolvesCount < 5)
{
Console.WriteLine("Run Away");
}
else
{
Console.WriteLine("Attack the lion!");
}
}
}
class Lion
{
public void CounerAttack()
{
if (Wolf.WolvesCount <= 7)
{
Console.WriteLine("the lion Attack lion win");
}
else Console.WriteLine("wolf is win!");
}
}