回复 2楼 yhlvht
o ,会了
主要是对构造函数和属性不熟悉,我写的你看看有什么需要改进的没.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace fight
{
public class Footman
{
int id;
public int Id1
{
get { return id; }
set
{
id = value;
}
}
string name;
public string Name
{
get { return name; }
set
{
name = value;
}
}
int life;
public int Life
{
get { return life; }
set
{
life = value;
}
}
int attackLow;
public int AttackLow1
{
get { return attackLow; }
set
{
attackLow = value;
}
}
int attackhigh;
public int Attackhigh1
{
get { return attackhigh; }
set
{
attackhigh = value;
}
}
public Footman()
{}
}
public class Battle
{
public static void Fight(Footman a, Footman b)
{
Random r = new Random();
int attack1,attack2;
int lf1, lf2;
do
{
attack1 = r.Next(a.AttackLow1, a.Attackhigh1);
attack2 = r.Next(a.AttackLow1, a.Attackhigh1);
lf2 = b.Life - attack1;
b.Life = lf2;
Console.WriteLine("{0}攻击{1},{2}掉了{3}滴血,还剩{4}滴血", a.Name, b.Name, b.Name, attack1, lf2);
lf1 = a.Life - attack2;
a.Life = lf1;
Console.WriteLine("{0}攻击{1},{2}掉了{3}滴血,还剩{4}滴血", b.Name, a.Name, a.Name, attack2, lf1);
if (b.Life <= 0)
{
Console.WriteLine("{0}被{1}殴打死了",b.Name,a.Name);
}
else if(a.Life <= 0)
{
Console.WriteLine("{0}被{1}殴打死了",a.Name , b.Name);
}
} while (a.Life > 0 && b.Life > 0);
}
static void Main(string[] args)
{
Footman a=new Footman ();
Footman b= new Footman();
a.Id1 = 1;
b.Id1 = 2;
a.Name = "小飞";
b.Name = "小田";
a.Life = 100;
b.Life = 100;
a.AttackLow1 = 8;
b.AttackLow1 = 8;
a.Attackhigh1 = 12;
b.Attackhigh1 = 12;
Console.WriteLine("{0}的生命是{1},最小攻击{2},最大攻击{3}",a.Name ,a.Life ,a.AttackLow1 ,a.Attackhigh1);
Console.WriteLine("{0}的生命是{1},最小攻击{2},最大攻击{3}", b.Name, b.Life, b.AttackLow1, b.Attackhigh1);
Fight(a, b);
Console.ReadLine();
}
}
}