小小大战

HeroDemo类

package com.zhcpt.sixtest;

import java.util.Random;

public class HeroDemo {
    public static void main(String[] args) {

        int[] SkillHurt ={50,60,70,100};

        String[] Skillcxk = {"唱","跳","Rap","篮球"};
        Hero cxk = new Hero("蔡先生",Skillcxk,SkillHurt,700);

        String[] Skillwyf = {"吹","拉","谈","skr"};
        Hero wyf = new Hero("吴帅气",Skillwyf,SkillHurt,700);

        Random random = new Random();
        int i = random.nextInt(2);
        System.out.println("开始对战,摇骰子决定谁先开始");
        while (true){
            if (i==0){
                System.out.println("蔡先生先出手攻击吴帅气");
                if (cxk.getHp()<=0){
                    System.out.println(cxk.getName()+"血量低于0,无法继续攻击"+wyf.getName()+"获胜");
                    break;
                }
                cxk.attack(wyf);
                if (wyf.getHp() <= 0) {
                    System.out.println(wyf.getName() + "xiedi" + cxk.getName() + "获胜");
                }
                wyf.attack(cxk);
            } else if (i == 1) {
                System.out.println("吴亦凡开始攻击蔡徐坤");
                if (wyf.getHp() <= 0) {
                    System.out.println(wyf.getName() + "血量低,无法攻击" + cxk.getName() + "获胜");
                    break;
                }
                wyf.attack(cxk);

                if (cxk.getHp() <= 0) {
                    System.out.println(cxk.getName() + "血量为0" + wyf.getName() + "获胜");
                }
                cxk.attack(wyf);
            }
        }
    }
}

Hero类

package com.zhcpt.sixtest;

import java.util.Random;

public class Hero {
    private String Name;
    private String[] Skill;
    private int[] SkillHurts;
    private double Hp;

    public Hero() {
    }

    public Hero(String name, String[] skill, int[] skillHurts, double hp) {
        Name = name;
        Skill = skill;
        SkillHurts = skillHurts;
        Hp = hp;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String[] getSkill() {
        return Skill;
    }

    public void setSkill(String[] skill) {
        Skill = skill;
    }

    public int[] getSkillHurts() {
        return SkillHurts;
    }

    public void setSkillHurts(int[] skillHurts) {
        SkillHurts = skillHurts;
    }

    public double getHp() {
        return Hp;
    }

    public void setHp(double hp) {
        Hp = hp;
    }
    public  void attack(Hero otherHero) {
        Random random = new Random();
        int SkillNum = random.nextInt(Skill.length);
        String Skill = this.Skill[SkillNum];
        double SkillHurt = otherHero.SkillHurts[SkillNum];
        otherHero.Hp = otherHero.Hp - SkillHurt;
        System.out.println(this.Name + "使用了" + Skill + "技能,对"
                + otherHero.getName() + "造成了" + SkillHurt
                + "伤害" + otherHero.getName() + "现在还剩" + otherHero.getHp() + "血量");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值