-2
public static void fbdeathcheck() {
if (php <= 0) {
}
}
private static int FBenemyhp = 10, FBenemystr = 2, FBenemydef = 2, FBenemyspd = 2, FBenemyatk = 1;
public static void firstbattle(String[] args) {
String nextmovefirstbattle = "";
int dodgechancefb = 0;
while(FBenemyhp > 0 && php > 0) {
System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n");
System.out.println("-----BATTLE MODE-----");
System.out.println("Enemy | HP " + FBenemyhp + " |");
if (nextmovefirstbattle.equalsIgnoreCase("dodge") && dodgechancefb == 1) {
System.out.println("DODGED!");
}
else {
System.out.println("");
}
System.out.println("Commands:");
System.out.println("Attack, Dodge");
System.out.println("");
System.out.println("You | HP " + php + " |");
System.out.println("---------------------");
nextmovefirstbattle = scan.nextLine();
while (!nextmovefirstbattle.equalsIgnoreCase("attack") && !nextmovefirstbattle.equalsIgnoreCase("dodge")) {
nextmovefirstbattle = scan.nextLine();
}
if (nextmovefirstbattle.equalsIgnoreCase("attack")) {
if (FBenemyspd > pspeed){
php = php - FBenemyatk; //Enemy attacks player
FBenemyhp = FBenemyhp - patk; //Player attacks Enemy
}
else if (FBenemyspd < pspeed) {
FBenemyhp = FBenemyhp - patk; //Player attacks enemy
php = php - FBenemyatk; //Enemy attacks player
}
else {
int chancefb = rand.nextInt(2);
if (chancefb == 0) {
FBenemyhp = FBenemyhp - patk; //Player attacks enemy
php = php - FBenemyatk; //Enemy attacks player
}
else if (chancefb == 1) {
php = php - FBenemyatk; //Enemy attacks player
FBenemyhp = FBenemyhp - patk; //Player attacks Enemy
}
}
}
else if(nextmovefirstbattle.equalsIgnoreCase("dodge")) {
dodgechancefb = rand.nextInt(10);
if(dodgechancefb == 1) {
php = php + 0;
}
else {
php = php - FBenemyatk; //Enemy hits player because dodge failed.
}
}
}
php = 15;
}
基本上,如果我是例如後把fbdeathcheck(),如果方法返回true,代碼如何停止?
php = php - FBenemyatk;
我將如何讓firstbattle()方法停止,如果fbdeathcheck()是真的嗎? 的fbdeathcheck()方法的目的是停止戰鬥,當健康點達到0.1