Hero.java
package game;
import java.u;
public class Hero {
String name; //名字
String [ ] skills;//技能
double [ ] skillHurts;//技能伤害
double hp=700;//初始血量
public void attack(Hero otherHero) {
//生成一个随机数
Random rd=new Random();
//生成一个随机数,用来用列表选择一个技能
int index=rd.nextIn);
//用随机数,选取一个技能来
String skill=skills[index];
//用随机数,选出英雄对应的技能伤害
double skillHurt=skillHurts[index];
//对其他英雄造成伤害
o;
Sy(name+"使用了"+skill+"技能,对"+o;造成了"+skillHurt+"点伤害"+o;还剩"+o;点血");
}
}
Te
package game;
import java.u;
public class Test {
public static void main(String[] args) {
Random rd = new Random();
int index = rd.nextInt(2);
Hero ngls= new Hero();
Hero ln = new Hero();
ngls.name = "尼古拉斯·赵四";
String[] skills = { "踢腿", "拳击", "背击", "话痨" };
ngls.skills = skills;
double[] skillHurts = { 50, 70, 80, 150 };
ngls.skillHurts = skillHurts;
ln.name = "刘能";
String[] skills1 = { "左勾拳", "结巴", "右勾拳", "诡计" };
ln.skills = skills1;
double[] skillHurts1 = { 50, 70, 80, 100 };
ln.skillHurts = skillHurts1;
while (true) {
if (index == 1) {
ngls.attack(ln);
if <= 0) {
Sy + "血量低于或等于0,无法攻击" + ln.name + "获胜");
break;
}
ln.attack(ngls);
if <= 0) {
Sy + "血量低于或等于0,无法攻击" + ngls.name + "获胜");
break;
}
} else {
ngls.attack(ln);
if <= 0) {
Sy + "血量低于或等于0,无法攻击" + ln.name + "获胜");
break;
}
}
}
}
}