蔡徐坤vs吴亦凡
public class Demo100 {
static class Hero{
private String name;
private String [] skill;
private int[] skillHurts;
private double hp;
public String getName(){
return name;
}
public void setName(String name){
this.name=name;
}
public String [] getSkill(){
return skill;
}
public void setSkill(String [] skill){
this.skill=skill;
}
public int [] getSKillHurts(){
return skillHurts;
}
public void setSkillHurts(int[] skillHurts){
this.skillHurts=skillHurts;
}
public double getHp(){
return hp;
}
public void setHp(double hp){
this.hp=hp;
}
public Hero(){
super();
}
public Hero(String name,String [] skill,int[] skillHurts,double hp){
super();
this.name=name;
this.skill=skill;
this.skillHurts=skillHurts;
this.hp=hp;
}
public void attack(Hero otherHero){
Random r=new Random();
int skillNum= r.nextInt(skill.length);
String skill=this.skill[skillNum];
double hurts=otherHero.skillHurts[skillNum];
otherHero.hp=otherHero.hp-hurts;
System.out.println(this.name+"使出了"+skill+"技能,对"+otherHero.getName()+"造成了"+hurts+"点伤害"+otherHero.getName()
+"现在还剩"+otherHero.hp+"血量");
}
}
public static class HeroDemo {
public static void main(String[] args) {
int[] skillHurts = {50, 70, 80, 100};
String[] skillcxk = {"摸屁屁", "摸奶奶", "亲嘴唇", "双管齐下警告"};
Hero cxk = new Hero("时雨啊", skillcxk, skillHurts, 700);
String[] skillwyf = {"摸钩子", "摸奈子", "摸牛子", "嘬奶子警告"};
Hero wyf = new Hero("俊俊啊", skillwyf, skillHurts, 700);
Random r = new Random();
int i = r.nextInt(2);
System.out.println("vs开始,首先摇骰子随机判断谁出手");
if (i == 0) {
System.out.println("俊俊优先亲时雨");
while (true) {
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() + "血量低于或等于0,无法继续亲亲" + cxk.getName() + "获胜");
}
wyf.attack(cxk);
}
} else if (i == 1) {
System.out.println("时雨优先亲俊俊");
while(true){if (wyf.getHp() <= 0) {
System.out.println(wyf.getName() + "血量低于或等于0,无法继续亲亲" + cxk.getName() + "获胜");
break;
}
wyf.attack(cxk);
if (cxk.getHp() <= 0) {
System.out.println(cxk.getName() + "血量低于或等于0,无法继续亲亲" + wyf.getName() + "获胜");
break;
}
cxk.attack(wyf);
}
}
}
}