package com.lovo;
public class Pk {
public static boolean hasAliveMonster(Monster[] ms) {
for(int i = 0; i < ms.length; i++) {
if(ms[i].isAlive()) {
return true;
}
}
return false;
}
public static void main(String[] args) throws Exception {
Ultraman u = new Ultraman("董卓");
Monster[] ms = {
new Monster("赵云"),
new Monster("关羽"),
new Monster("张飞"),
new Monster("刘备"),
new Monster("黄盖")
};
int round = 1;
do {
System.out.println("——————————第" + round++ + "回合——————————");
Monster m = null;
do {
int mIndex = (int) (Math.random() * ms.length); //找到活得在攻击..
m = ms[mIndex];
} while(!m.isAlive());
m.attack(u);
System.out.println(m.getName() + "小怪兽攻击奥特曼");
System.out.println(u);
if(u.getHp() > 0) {
u.setMp(u.getMp() + 5);
double rate = Math.random();
if(rate <= 0.8) {
System.out.println("奥特曼攻击小怪兽");
u.attack(m);
}
else if(rate <= 0.9) {
System.out.println("奥特曼使用究极必杀技!!!!");
u.hugeAttack(m);
}
else {
if(u.getMp() >= 30) {
System.out.println("奥特曼使用魔法攻击");
u.magicAttack(ms);
}
else {
System.out.println("奥特曼使用魔法失败");
}
}
for(Monster tempMonster : ms) {
System.out.println(tempMonster);
}
}
} while(u.getHp() > 0 && hasAliveMonster(ms));
if(u.getHp() > 0) {
System.out.println("奥特曼胜利!!!");
}
else {
System.out.println("小怪兽胜利!!!");
}
}
}