定义一个方法实现奥特曼攻击小怪兽,定义一个方法实现小怪兽攻击奥特曼

本文介绍了如何使用C#编程语言来定义两个方法,分别是奥特曼攻击小怪兽和小怪兽攻击奥特曼的逻辑,通过代码实现战斗过程的模拟。
摘要由CSDN通过智能技术生成
 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;
       
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值