public void setName(String name) {
this.name = name;
}
public Integer getHP() {
return HP;
}
public void setHP(Integer HP) {
this.HP = HP;
}
@Override
public String toString() {
return "Boss{" +
"name='" + name + '\'' +
", HP=" + HP +
'}';
}
public void shang(Integer i) throws Exception {
this.HP=this.HP-i;
if (this.HP<=0){
return;
}
System.out.println("Boss剩余血量"+this.HP);
}
}
public class Player {
String name;
int HP;
public Player(String name, int HP) {
this.name = name;
this.HP = HP;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHP() {
return HP;
}
public void setHP(int HP) {
this.HP = HP;
}
public Player() {
}
@Override
public String toString() {
return "Player{" +
"name='" + name + '\'' +
", HP=" + HP +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Player player = (Player) o;
return HP == player.HP &&
Objects.equals(name, player.name);
}
@Override
public int hashCode() {
return Objects.hash(name, HP);
}
public void shang(int i) throws Exception {
this.HP=this.HP-i;
if (this.HP <= 0){
throw new Exception("死亡,游戏结束");
}
System.out.println(name+"剩余血量"+this.HP);
}
}
public class Test extends Thread {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
Random r = new Random();
System.out.println("请输入玩家名字:");
Player player = new Player(sc.next(), 600 + r.nextInt(800));
System.out.println("玩家" + player.name + "游戏开始");
Boss boss1 = new Boss("图图", 30000);
Boss boss2 = new Boss("杭杭", 28000);
Boss boss3 = new Boss("卓卓", 23000);
while (true) {
ArrayList<Boss> list = new ArrayList<>();
list.add(boss1);
list.add(boss2);
list.add(boss3);
int q = r.nextInt(3);
Boss boss = list.get(q);
System.out.println("遭遇Boss" + boss.name);
int MP = 0;
while (true) {
System.out.println("Boss发动攻击");
double z = (double) r.nextInt(800) / 1000;
double b = 0.6 + z;
int c = (int) (300 * b);
player.shang(c);
Thread.sleep(3000);
if (boss.HP <= 0) {
break;
}
Thread.sleep(1000);
int x = r.nextInt(400);
double y = (double) x / 2000;
double bei = 0.8 + y;
Integer i = 0;
String[] s = {"崩山裂地斩", "拔刀斩", "怒意狂澜", "冥想"};
int d = r.nextInt(4);
String k = s[d];
System.out.println("玩家" + player.name + "发动技能" + k);
if (k.equals("崩山裂地斩")) {
i = (int) (2000 * bei);
} else if (k.equals("拔刀斩")) {
i = (int) (1200 * bei);
MP += 5 * bei;
player.HP += i * 0.3;
} else if (k.equals("怒意狂澜")) {
i = (int) (400 * bei);
MP += 5 * bei;
player.HP += i;
} else if (k.equals("冥想")) {
MP += 30 * bei;
player.HP += 100 * bei;
} else {
System.out.println("攻击失败,请重试");
continue;
}
if (MP > 100) {
i = (int) (20000 * bei);
System.out.println("MP值充满,玩家“+player.name+”发动终极技能:");
System.out.println("********帝血弑天********");
System.out.println("对boss" + boss.name + "造成" + i + "点伤害");
MP = 0;
}
boss.shang(i);
Thread.sleep(2000);
}
}
}