struct Altman//奥特曼
{
public string name;
public int ack;
public int def;
public int hp;
public Altman(string name, int ack, int def, int hp)
{
this.name = name;
this.ack = ack;//攻击力
this.def = def;//防御力
this.hp = hp;//血量
}
public void Atk(ref Monster1 monster)//奥特曼打怪兽
{
int num = ack - monster.ack;//奥特曼的伤害量
if (num <= 0)
num = 1;
monster.hp = monster.hp-num;//怪兽剩余血量
if (monster.hp < 0)
monster.hp = 0;
Console.WriteLine("{0}攻击了{1},造成了{2}点伤害,{3}剩余血量{4}",
name, monster.name, num, monster.name, monster.hp);
}
}
struct Monster1
{
public string name;
public int ack;
public int def;
public int hp;
定义一个方法实现奥特曼攻击小怪兽,定义一个方法实现小怪兽攻击奥特曼
本文介绍了如何使用C#编程语言来定义两个方法,分别是奥特曼攻击小怪兽和小怪兽攻击奥特曼的逻辑,通过代码实现战斗过程的模拟。
摘要由CSDN通过智能技术生成