Programm verhält sich in Eclipse anders, als ein eigenständiges Programm

SchalliLP

Aktives Mitglied
Hallo,
ich habe ein Spiel für die Schule programmiert.
Mein Problem ist nun folgendes:

Wenn ich das Programm
[Java]
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

public class Spiel {
public static void main(String[] args) {

//Objekte
Scanner in = new Scanner(System.in);
Random rand = new Random();


//Spielvariablen
String[] enemies = { "Skelett", "Zombie", "Riesenratte", "Goblin", "Magier", "SchalliLP's Klon", "Riesenspinne" };
int maxEnemyHealth = 75;
int enemyAttakDamage = 25;
int Score = 0;

//SpielerVariablen
boolean Fail = false;
boolean Exit=false;

int Schwert = 0;
int Rüstung = 0;
int Helfer = 0;
boolean Exit2 = false;


int health = 100;
int attakDamage = 50;
int numHealthPotions = 3;
int healthPotionHealAmount = 30;
int healthPotionDropChance = 50;
int enemyHealth;
int PlayerGold = 0;
int PlayerGoldPlus;
int ZerfetzteKörperteileVonRandomGegnern = 0;
int ZerfetzteKörperteileVonRandomGegnernPlus;
boolean running = true;
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println(" --------------------------------------------");
System.out.println(" / / |");
System.out.println("-------------------------------------------- |");
System.out.println("| DungeonFighter V1.6.2 BETA BUILD | /");
System.out.println("--------------------------------------------");
System.out.println();
System.out.println();
System.out.println(" Willkommen im Dungeon");
label1288: while (running) {
System.out.println("--------------------------------------------");





enemyHealth = rand.nextInt(maxEnemyHealth);
int Scoremultiplier = enemyHealth;
int EnemyStartHealth = enemyHealth;
String enemy = enemies[rand.nextInt(enemies.length)];
if (enemy == "SchalliLP's Klon") {
Scoremultiplier = 100;
}
if (enemy == "SchalliLP's Klon") {
enemyHealth = 120;
}
if (enemyHealth < 5) {
enemyHealth = 5;
}
System.out.println("\t# " + enemy + " erscheint!#\n");
while (enemyHealth > 0) {
System.out.println("\tDeine HP: " + health);
System.out.println("\t" + enemy + " HP: " + enemyHealth);
System.out.println("\n\tWas willst du tun?");
System.out.println("\t1. Angreifen");
System.out.println("\t2. Heiltrank trinken");
System.out.println("\t3. Wegrennen!");





String input2 = in.nextLine();
if (input2.equals("1")) {
int damageDealt = rand.nextInt(attakDamage);
damageDealt = damageDealt + Schwert + Helfer;
int damageTaken = rand.nextInt(enemyAttakDamage);
damageTaken = damageTaken - Rüstung;
if (enemy == "SchalliLP's Klon") {
damageTaken = 15;
}
enemyHealth -= damageDealt;
health -= damageTaken;
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("--------------------------------------------");
System.out.println("\t> Du triffst " + enemy
+ " und verursachst " + damageDealt + " Schaden.");
System.out.println("\t> Du kassierst " + damageTaken
+ " Schaden!");
if (health < 1) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t> Du nahmst zu viel Schaden und bist zu geschwächt um weiterzumachen!");
Fail = true;
break;
}
} else if (input2.equals("2")) {
if (numHealthPotions > 0) {
health += healthPotionHealAmount;
numHealthPotions--;
for (int i = 0; i < 80; i++) {
System.out.println();
}
if (health > 100) {
health = 100;
}
System.out
.println("--------------------------------------------");
System.out
.println("\t Du trinkst einen heiltrank. Du hast "
+ healthPotionHealAmount
+ " HP dazu bekommen."
+ "\n\t> Du hast jetzt "
+ health
+ "HP."
+ "\n\t> Du hast "
+ numHealthPotions
+ " Heiltränke übrig.\n");
} else {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t Du hast keine Heiltränke mehr! Besiege Gegner um welche zu finden!\n");
if (health > 100) {
health = 100;
}
}
} else {
if (input2.equals("3")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("\t Du liefst weg vor: " + enemy
+ "!");
if (enemy == "SchalliLP's Klon") {
health -= 10;
}
if (health >= 1) {
break label1288;
}
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t> Du nahmst zu viel Schaden und bist zu geschwächt um weiterzumachen!");
Fail = true;
break;
}
System.out.println("\tUngültieger Befehl!");
}
}
if (health < 1) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("Du kriechst aus dem Dungeon, geschwächt vom kampf.");
Fail = true;
break;
}
System.out.println("--------------------------------------------");
System.out.println(" # " + enemy + " wurde besiegt! #");
System.out.println(" # Du hast " + health + " HP übrig. #");
Score += Scoremultiplier;
if (EnemyStartHealth < 30) {
if ((rand.nextInt(100) < EnemyStartHealth) || (enemy == "SchalliLP's Klon")) {
numHealthPotions++;

System.out.println(" # " + enemy + " Hat einen Heiltrank fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + numHealthPotions + " Heiltrank(s). # ");
}



} else if (rand.nextInt(100) < healthPotionDropChance) {
numHealthPotions++;

System.out.println(" # " + enemy
+ " Hat einen Heiltrank fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + numHealthPotions
+ " Heiltrank(s). # ");
}
PlayerGoldPlus = rand.nextInt(9) + 1;
PlayerGold=PlayerGold + PlayerGoldPlus;

System.out.println(" # " + enemy + " Hat "+PlayerGoldPlus+ " Gold fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + PlayerGold + " Gold. # ");

ZerfetzteKörperteileVonRandomGegnernPlus = rand.nextInt(9) + 1;
ZerfetzteKörperteileVonRandomGegnern=ZerfetzteKörperteileVonRandomGegnern + ZerfetzteKörperteileVonRandomGegnernPlus;

System.out.println(" # " + enemy + " Hat "+ZerfetzteKörperteileVonRandomGegnernPlus+ " ZerfetzteKörperteile fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + ZerfetzteKörperteileVonRandomGegnern + " ZerfetzteKörperteileVonRandomGegnern. # ");



System.out.println("--------------------------------------------");
System.out.println("Was möchtest du jetzt tun?");
System.out.println("1. Weiter kämpfen");
System.out.println("2. Dungeon verlassen");

String input = in.nextLine();
while ((!input.equals("1")) && (!input.equals("2"))) {
System.out.println("Ungültiger Befehl!");
input = in.nextLine();
}
if (input.equals("1")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du setzt dein Abenteuer fort!");
} else if (input.equals("2")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du verlässt den Dungeon erfolgreich nach deinen Abenteuern!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du?");
System.out.println("1. Zum Shop");
System.out.println("2. Zum Nekromanten");
System.out.println("3. Zur Bar");
System.out.println("4. Zurück in den Dungeon");
System.out.println("5. Spiel beenden");
input = in.nextLine();

if (input.equals("1")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Shop!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Schwerter");
System.out.println("2. Rüstungen");
System.out.println("3. Heilitems");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();





if (input.equals("1")) {

System.out.println("Schwerter!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Holzschwert (100G)");
System.out.println("2. Steinschwert (300G)");
System.out.println("3. Eisenschwert (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Schwert = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Schwert=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Schwert=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}




}
if (input.equals("2")) {

System.out.println("Rüstungen!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Lederrüstung (100G)");
System.out.println("2. Eisenrüstung (300G)");
System.out.println("3. Diamantrüstung (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Rüstung = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Rüstung=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Rüstung=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}





}
if (input.equals("3")) {

System.out.println("Heilitems!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. 1 Heiltrank (50G)");
System.out.println("2. 10 Heiltränke (500G)");
System.out.println("3. 100 Heiltränke (5000G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (PlayerGold>=50){

numHealthPotions = numHealthPotions + 1;
PlayerGold = PlayerGold - 50;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=500){

numHealthPotions = numHealthPotions + 10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=5000){

numHealthPotions = numHealthPotions + 100;
PlayerGold = PlayerGold - 5000;

}else { input = "100"; }

}





}





}
if (input.equals("2")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Nekromanten!");
System.out.println("--------------------------------------------");
System.out.println("Soll ich einen Verbündeten beschwören?");
System.out.println("1. Ja (200 ZerfetzteKörperteileVonRandomGegnern)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (ZerfetzteKörperteileVonRandomGegnern>=200){

ZerfetzteKörperteileVonRandomGegnern = ZerfetzteKörperteileVonRandomGegnern - 200;
Helfer = 15;


}else { input = "100"; }

}




}
if (input.equals("3")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zur bar!");
System.out.println("--------------------------------------------");
System.out.println("Willst du dich vollheilen?");
System.out.println("1. Ja (100)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

PlayerGold = PlayerGold - 100;
health = 100;


}else { input = "100"; }

}


}




if (input.equals("5")) {
Exit=true;
Exit2=true;
}

if (!(input.equals("1"))&&!(input.equals("2"))&&!(input.equals("3"))&&!(input.equals("4"))&&!(input.equals("5"))) {
while (!(input.equals("1"))&&!(input.equals("2"))&&!(input.equals("3"))&&!(input.equals("4"))&&!(input.equals("5"))) {
for (int i = 0; i < 80; i++) {
System.out.println();
}



System.out.println("Was möchtest du?");
System.out.println("1. Zum Shop");
System.out.println("2. Zum Nekromanten");
System.out.println("3. Zur Bar");
System.out.println("4. Zurück in den Dungeon");
System.out.println("5. Spiel beenden");
input = in.nextLine();

if (input.equals("1")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Shop!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Schwerter");
System.out.println("2. Rüstungen");
System.out.println("3. Heilitems");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();





if (input.equals("1")) {

System.out.println("Schwerter!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Holzschwert (100G)");
System.out.println("2. Steinschwert (300G)");
System.out.println("3. Eisenschwert (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Schwert = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Schwert=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Schwert=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}




}
if (input.equals("2")) {

System.out.println("Rüstungen!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Lederrüstung (100G)");
System.out.println("2. Eisenrüstung (300G)");
System.out.println("3. Diamantrüstung (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Rüstung = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Rüstung=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Rüstung=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}





}
if (input.equals("3")) {

System.out.println("Heilitems!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. 1 Heiltrank (50G)");
System.out.println("2. 10 Heiltränke (500G)");
System.out.println("3. 100 Heiltränke (5000G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (PlayerGold>=50){

numHealthPotions = numHealthPotions + 1;
PlayerGold = PlayerGold - 50;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=500){

numHealthPotions = numHealthPotions + 10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=5000){

numHealthPotions = numHealthPotions + 100;
PlayerGold = PlayerGold - 5000;

}else { input = "100"; }

}





}





}
if (input.equals("2")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Nekromanten!");
System.out.println("--------------------------------------------");
System.out.println("Soll ich einen Verbündeten beschwören?");
System.out.println("1. Ja (200 ZerfetzteKörperteileVonRandomGegnern)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (ZerfetzteKörperteileVonRandomGegnern>=200){

ZerfetzteKörperteileVonRandomGegnern = ZerfetzteKörperteileVonRandomGegnern - 200;
Helfer = 15;


}else { input = "100"; }

}




}
if (input.equals("3")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zur bar!");
System.out.println("--------------------------------------------");
System.out.println("Willst du dich vollheilen?");
System.out.println("1. Ja (100)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

PlayerGold = PlayerGold - 100;
health = 100;


}else { input = "100"; }

}


}

}
}


if ((Fail)||(Exit)&&(Exit2)) {
break;
}
}
}
for (int i = 0; i < 80; i++) {
System.out.println();
}
if (Fail) {
Score /= 2;
}
System.out.println("#######################");
System.out.println("# DANKE FÜRS SPIELEN! #");
System.out.println("#######################");
System.out.println();
System.out.println("Dein Score ist " + Score);
System.out.println("Name: ");
for (int i = 0; i < 9; i++) {
System.out.println();
}
String input = in.nextLine();

String name = input;
try {
FileWriter write = new FileWriter("text.txt", true);
PrintWriter text = new PrintWriter(write);
text.println(name + ":");
text.println(Score);
text.println();
text.flush();
write.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
for (int i = 0; i < 100; i++) {
System.out.println();
}
}
}
[/Java]

in Eclipse ausführe kann man in den Shop gelangen...
Exportiere ich es kann man nicht in den Shop.
Außerdem ist es unmöglich zu fliehen ohne in den Endscreen zu kommen und ich finde den Fehler dabei nicht selber obwohl ich 1 Stunde danach gesucht habe.

kann mir jemand bei einem (oder beiden) Problemen helfen?

Danke an alle die es probieren

MfG SchalliLP
 
Das exportieren oder das ausführen ohne Endscreen beim flüchten? Könntest du das spezifizieren bitte?

EDIT:
Ok ich habe es exportiert bekommen.
Das mit dem Weglaufen klappt allerdings immer noch nicht.
Hat jemand einen Lösungsansatz oder eine Lösung?
 
Zuletzt bearbeitet:
Klappt nicht ist eine Fehlerbeschreibung mit der niemand etwas anfangen kann.

Wenn du uns mal etwas genauer sagst was wie nicht funktioniert dann können wir vielleicht auch helfen.

Gruß

Claus
 
Ups. da habe ich mich etwas wage ausgedrückt. Entschuldiegung.
Wenn man im kampf 3 eingibt (Weglaufen wählt)
[Java]
System.out.println("\n\tWas willst du tun?");
System.out.println("\t1. Angreifen");
System.out.println("\t2. Heiltrank trinken");
System.out.println("\t3. Wegrennen!");
[/Java]

Z. 78 ff

Kommt der Endscreen anstatt ein neues Monster.

[Java]
System.out.println("#######################");
System.out.println("# DANKE FÜRS SPIELEN! #");
System.out.println("#######################");
System.out.println();
System.out.println("Dein Score ist " + Score);
System.out.println("Name: ");
for (int i = 0; i < 9; i++) {
System.out.println();
}
String input = in.nextLine();

String name = input;
try {
FileWriter write = new FileWriter("text.txt", true);
PrintWriter text = new PrintWriter(write);
text.println(name + ":");
text.println(Score);
text.println();
text.flush();
write.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
for (int i = 0; i < 100; i++) {
System.out.println();
}
}
[/Java]

In der Alten Version

[Java]
//Alte Version
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

public class Spiel {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Random rand = new Random();

String[] enemies = { "Skelett", "Zombie", "Riesenratte", "Goblin",
"Magier", "SchalliLP's Klon", "Riesenspinne" };
int maxEnemyHealth = 75;
int enemyAttakDamage = 25;
int Score = 0;

boolean Fail = false;

int health = 100;
int attakDamage = 50;
int numHealthPotions = 3;
int healthPotionHealAmount = 30;
int healthPotionDropChance = 50;

boolean running = true;
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println(" --------------------------------------------");
System.out.println(" / / |");
System.out.println("-------------------------------------------- |");
System.out.println("| DungeonFighter V1.6.2 BETA BUILD | /");
System.out.println("--------------------------------------------");
System.out.println();
System.out.println();
System.out.println(" Willkommen im Dungeon");
label1288: while (running) {
System.out.println("--------------------------------------------");

int enemyHealth = rand.nextInt(maxEnemyHealth);
int Scoremultiplier = enemyHealth;
int EnemyStartHealth = enemyHealth;
String enemy = enemies[rand.nextInt(enemies.length)];
if (enemy == "SchalliLP's Klon") {
Scoremultiplier = 100;
}
if (enemy == "SchalliLP's Klon") {
enemyHealth = 120;
}
if (enemyHealth < 5) {
enemyHealth = 5;
}
System.out.println("\t# " + enemy + " erscheint!#\n");
while (enemyHealth > 0) {
System.out.println("\tDeine HP: " + health);
System.out.println("\t" + enemy + " HP: " + enemyHealth);
System.out.println("\n\tWas willst du tun?");
System.out.println("\t1. Angreifen");
System.out.println("\t2. Heiltrank trinken");
System.out.println("\t3. Wegrennen!");

String input = in.nextLine();
if (input.equals("1")) {
int damageDealt = rand.nextInt(attakDamage);
int damageTaken = rand.nextInt(enemyAttakDamage);
if (enemy == "SchalliLP's Klon") {
damageTaken = 15;
}
enemyHealth -= damageDealt;
health -= damageTaken;
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("--------------------------------------------");
System.out.println("\t> Du triffst " + enemy
+ " und verursachst " + damageDealt + " Schaden.");
System.out.println("\t> Du kassierst " + damageTaken
+ " Schaden!");
if (health < 1) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t> Du nahmst zu viel Schaden und bist zu geschwächt um weiterzumachen!");
Fail = true;
break;
}
} else if (input.equals("2")) {
if (numHealthPotions > 0) {
health += healthPotionHealAmount;
numHealthPotions--;
for (int i = 0; i < 80; i++) {
System.out.println();
}
if (health > 100) {
health = 100;
}
System.out
.println("--------------------------------------------");
System.out
.println("\t Du trinkst einen heiltrank. Du hast "
+ healthPotionHealAmount
+ " HP dazu bekommen."
+ "\n\t> Du hast jetzt "
+ health
+ "HP."
+ "\n\t> Du hast "
+ numHealthPotions
+ " Heiltränke übrig.\n");
} else {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t Du hast keine Heiltränke mehr! Besiege Gegner um welche zu finden!\n");
if (health > 100) {
health = 100;
}
}
} else {
if (input.equals("3")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("\t Du liefst weg vor: " + enemy
+ "!");
if (enemy == "SchalliLP's Klon") {
health -= 10;
}
if (health >= 1) {
break label1288;
}
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t> Du nahmst zu viel Schaden und bist zu geschwächt um weiterzumachen!");
Fail = true;
break;
}
System.out.println("\tUngültieger Befehl!");
}
}
if (health < 1) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("Du kriechst aus dem Dungeon, geschwächt vom kampf.");
Fail = true;
break;
}
System.out.println("--------------------------------------------");
System.out.println(" # " + enemy + " wurde besiegt! #");
System.out.println(" # Du hast " + health + " HP übrig. #");
Score += Scoremultiplier;
if (EnemyStartHealth < 30) {
if ((rand.nextInt(100) < EnemyStartHealth)
|| (enemy == "SchalliLP's Klon")) {
numHealthPotions++;

System.out.println(" # " + enemy
+ " Hat einen Heiltrank fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + numHealthPotions
+ " Heiltrank(s). # ");
}
} else if (rand.nextInt(100) < healthPotionDropChance) {
numHealthPotions++;

System.out.println(" # " + enemy
+ " Hat einen Heiltrank fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + numHealthPotions
+ " Heiltrank(s). # ");
}
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du jetzt tun?");
System.out.println("1. Weiter kämpfen");
System.out.println("2. Dungeon verlassen");

String input = in.nextLine();
while ((!input.equals("1")) && (!input.equals("2"))) {
System.out.println("Ungültiger Befehl!");
input = in.nextLine();
}
if (input.equals("1")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du setzt dein Abenteuer fort!");
} else if (input.equals("2")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("Du verlässt den Dungeon erfolgreich nach deinen Abenteuern!");
break;
}
}
for (int i = 0; i < 80; i++) {
System.out.println();
}
if (Fail) {
Score /= 2;
}
System.out.println("#######################");
System.out.println("# DANKE FÜRS SPIELEN! #");
System.out.println("#######################");
System.out.println();
System.out.println("Dein Score ist " + Score);
System.out.println("Name: ");
for (int i = 0; i < 9; i++) {
System.out.println();
}
String input = in.nextLine();

String name = input;
try {
FileWriter write = new FileWriter("text.txt", true);
PrintWriter text = new PrintWriter(write);
text.println(name + ":");
text.println(Score);
text.println();
text.flush();
write.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
for (int i = 0; i < 100; i++) {
System.out.println();
}
}
}
[/Java]

Funktioniert das fliehen noch.
ich hoffe das war etwas klarer ausgedrückt 😉
 
Ich habe mit meinem Bruder nun nach etwas Co operativem durchgucken die Lösung gefunden. trotzdem Danke!
An alle die es interessiert hier der gefixte Code:
[Java]
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

public class Spiel {
public static void main(String[] args) {

//Objekte
Scanner in = new Scanner(System.in);
Random rand = new Random();


//Spielvariablen
String[] enemies = { "Skelett", "Zombie", "Riesenratte", "Goblin", "Magier", "SchalliLP's Klon", "Riesenspinne" };
int maxEnemyHealth = 75;
int enemyAttakDamage = 25;
int Score = 0;

//SpielerVariablen
boolean Fail = false;
boolean Exit=false;
int weggelaufen = 0;

int Schwert = 0;
int Rüstung = 0;
int Helfer = 0;
boolean Exit2 = false;


int health = 100;
int attakDamage = 50;
int numHealthPotions = 3;
int healthPotionHealAmount = 30;
int healthPotionDropChance = 50;
int enemyHealth;
int PlayerGold = 0;
int PlayerGoldPlus;
int ZerfetzteKörperteileVonRandomGegnern = 0;
int ZerfetzteKörperteileVonRandomGegnernPlus;
boolean running = true;
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println(" --------------------------------------------");
System.out.println(" / / |");
System.out.println("-------------------------------------------- |");
System.out.println("| DungeonFighter V1.6.2 BETA BUILD | /");
System.out.println("--------------------------------------------");
System.out.println();
System.out.println();
System.out.println(" Willkommen im Dungeon");
label1288: while (running) {
System.out.println("--------------------------------------------");





enemyHealth = rand.nextInt(maxEnemyHealth);
int Scoremultiplier = enemyHealth;
int EnemyStartHealth = enemyHealth;
String enemy = enemies[rand.nextInt(enemies.length)];
if (enemy == "SchalliLP's Klon") {
Scoremultiplier = 100;
}
if (enemy == "SchalliLP's Klon") {
enemyHealth = 120;
}
if (enemyHealth < 5) {
enemyHealth = 5;
}
System.out.println("\t# " + enemy + " erscheint!#\n");
while (enemyHealth > 0) {
System.out.println("\tDeine HP: " + health);
System.out.println("\t" + enemy + " HP: " + enemyHealth);
System.out.println("\n\tWas willst du tun?");
System.out.println("\t1. Angreifen");
System.out.println("\t2. Heiltrank trinken");
System.out.println("\t3. Wegrennen!");





String input2 = in.nextLine();
if (input2.equals("1")) {
int damageDealt = rand.nextInt(attakDamage);
damageDealt = damageDealt + Schwert + Helfer;
int damageTaken = rand.nextInt(enemyAttakDamage);
damageTaken = damageTaken - Rüstung;
if (enemy == "SchalliLP's Klon") {
damageTaken = 15;
}
enemyHealth -= damageDealt;
health -= damageTaken;
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("--------------------------------------------");
System.out.println("\t> Du triffst " + enemy
+ " und verursachst " + damageDealt + " Schaden.");
System.out.println("\t> Du kassierst " + damageTaken
+ " Schaden!");
if (health < 1) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t> Du nahmst zu viel Schaden und bist zu geschwächt um weiterzumachen!");
Fail = true;
break;
}
} else if (input2.equals("2")) {
if (numHealthPotions > 0) {
health += healthPotionHealAmount;
numHealthPotions--;
for (int i = 0; i < 80; i++) {
System.out.println();
}
if (health > 100) {
health = 100;
}
System.out
.println("--------------------------------------------");
System.out
.println("\t Du trinkst einen heiltrank. Du hast "
+ healthPotionHealAmount
+ " HP dazu bekommen."
+ "\n\t> Du hast jetzt "
+ health
+ "HP."
+ "\n\t> Du hast "
+ numHealthPotions
+ " Heiltränke übrig.\n");
} else {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t Du hast keine Heiltränke mehr! Besiege Gegner um welche zu finden!\n");
if (health > 100) {
health = 100;
}
}
} else {
if (input2.equals("3")) {
weggelaufen = 1;
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("\t Du liefst weg vor: " + enemy
+ "!");
if (enemy == "SchalliLP's Klon") {
health -= 10;
}
if (health < 1) {
Fail = true;
break label1288;
}
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("\t> Du liefst weg!");

break;
}
System.out.println("\tUngültieger Befehl!");
}
}
if (health < 1) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out
.println("Du kriechst aus dem Dungeon, geschwächt vom kampf.");
Fail = true;
break;
}

if (!(weggelaufen==1)) {
System.out.println("--------------------------------------------");
System.out.println(" # " + enemy + " wurde besiegt! #");
System.out.println(" # Du hast " + health + " HP übrig. #");
Score += Scoremultiplier;
if (EnemyStartHealth < 30) {
if ((rand.nextInt(100) < EnemyStartHealth) || (enemy == "SchalliLP's Klon")) {
numHealthPotions++;

System.out.println(" # " + enemy + " Hat einen Heiltrank fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + numHealthPotions + " Heiltrank(s). # ");
}



} else if (rand.nextInt(100) < healthPotionDropChance) {
numHealthPotions++;

System.out.println(" # " + enemy
+ " Hat einen Heiltrank fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + numHealthPotions
+ " Heiltrank(s). # ");
}
PlayerGoldPlus = rand.nextInt(9) + 1;
PlayerGold=PlayerGold + PlayerGoldPlus;

System.out.println(" # " + enemy + " Hat "+PlayerGoldPlus+ " Gold fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + PlayerGold + " Gold. # ");

ZerfetzteKörperteileVonRandomGegnernPlus = rand.nextInt(9) + 1;
ZerfetzteKörperteileVonRandomGegnern=ZerfetzteKörperteileVonRandomGegnern + ZerfetzteKörperteileVonRandomGegnernPlus;

System.out.println(" # " + enemy + " Hat "+ZerfetzteKörperteileVonRandomGegnernPlus+ " ZerfetzteKörperteile fallen gelassen! # ");
System.out.println(" # Du hast jetzt " + ZerfetzteKörperteileVonRandomGegnern + " ZerfetzteKörperteileVonRandomGegnern. # ");
}


System.out.println("--------------------------------------------");
System.out.println("Was möchtest du jetzt tun?");
System.out.println("1. Weiter kämpfen");
System.out.println("2. Dungeon verlassen");

String input = in.nextLine();
while ((!input.equals("1")) && (!input.equals("2"))) {
System.out.println("Ungültiger Befehl!");
input = in.nextLine();
}
if (input.equals("1")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du setzt dein Abenteuer fort!");
} else if (input.equals("2")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du verlässt den Dungeon erfolgreich nach deinen Abenteuern!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du?");
System.out.println("1. Zum Shop");
System.out.println("2. Zum Nekromanten");
System.out.println("3. Zur Bar");
System.out.println("4. Zurück in den Dungeon");
System.out.println("5. Spiel beenden");
input = in.nextLine();

if (input.equals("1")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Shop!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Schwerter");
System.out.println("2. Rüstungen");
System.out.println("3. Heilitems");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();





if (input.equals("1")) {

System.out.println("Schwerter!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Holzschwert (100G)");
System.out.println("2. Steinschwert (300G)");
System.out.println("3. Eisenschwert (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Schwert = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Schwert=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Schwert=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}




}
if (input.equals("2")) {

System.out.println("Rüstungen!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Lederrüstung (100G)");
System.out.println("2. Eisenrüstung (300G)");
System.out.println("3. Diamantrüstung (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Rüstung = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Rüstung=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Rüstung=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}





}
if (input.equals("3")) {

System.out.println("Heilitems!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. 1 Heiltrank (50G)");
System.out.println("2. 10 Heiltränke (500G)");
System.out.println("3. 100 Heiltränke (5000G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (PlayerGold>=50){

numHealthPotions = numHealthPotions + 1;
PlayerGold = PlayerGold - 50;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=500){

numHealthPotions = numHealthPotions + 10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=5000){

numHealthPotions = numHealthPotions + 100;
PlayerGold = PlayerGold - 5000;

}else { input = "100"; }

}





}





}
if (input.equals("2")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Nekromanten!");
System.out.println("--------------------------------------------");
System.out.println("Soll ich einen Verbündeten beschwören?");
System.out.println("1. Ja (200 ZerfetzteKörperteileVonRandomGegnern)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (ZerfetzteKörperteileVonRandomGegnern>=200){

ZerfetzteKörperteileVonRandomGegnern = ZerfetzteKörperteileVonRandomGegnern - 200;
Helfer = 15;


}else { input = "100"; }

}




}
if (input.equals("3")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zur bar!");
System.out.println("--------------------------------------------");
System.out.println("Willst du dich vollheilen?");
System.out.println("1. Ja (100)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

PlayerGold = PlayerGold - 100;
health = 100;


}else { input = "100"; }

}


}




if (input.equals("5")) {
Exit=true;
Exit2=true;
}

if (!(input.equals("1"))&&!(input.equals("2"))&&!(input.equals("3"))&&!(input.equals("4"))&&!(input.equals("5"))) {
while (!(input.equals("1"))&&!(input.equals("2"))&&!(input.equals("3"))&&!(input.equals("4"))&&!(input.equals("5"))) {
for (int i = 0; i < 80; i++) {
System.out.println();
}



System.out.println("Was möchtest du?");
System.out.println("1. Zum Shop");
System.out.println("2. Zum Nekromanten");
System.out.println("3. Zur Bar");
System.out.println("4. Zurück in den Dungeon");
System.out.println("5. Spiel beenden");
input = in.nextLine();

if (input.equals("1")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Shop!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Schwerter");
System.out.println("2. Rüstungen");
System.out.println("3. Heilitems");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();





if (input.equals("1")) {

System.out.println("Schwerter!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Holzschwert (100G)");
System.out.println("2. Steinschwert (300G)");
System.out.println("3. Eisenschwert (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Schwert = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Schwert=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Schwert=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}




}
if (input.equals("2")) {

System.out.println("Rüstungen!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. Lederrüstung (100G)");
System.out.println("2. Eisenrüstung (300G)");
System.out.println("3. Diamantrüstung (500G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

Rüstung = 2;
PlayerGold = PlayerGold - 100;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=300){

Rüstung=5;
PlayerGold = PlayerGold - 300;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=500){

Rüstung=10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}





}
if (input.equals("3")) {

System.out.println("Heilitems!");
System.out.println("--------------------------------------------");
System.out.println("Was möchtest du kaufen?");
System.out.println("1. 1 Heiltrank (50G)");
System.out.println("2. 10 Heiltränke (500G)");
System.out.println("3. 100 Heiltränke (5000G)");
System.out.println("4. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (PlayerGold>=50){

numHealthPotions = numHealthPotions + 1;
PlayerGold = PlayerGold - 50;

}else { input = "100"; }

}
if (input.equals("2")) {

if (PlayerGold>=500){

numHealthPotions = numHealthPotions + 10;
PlayerGold = PlayerGold - 500;

}else { input = "100"; }

}
if (input.equals("3")) {

if (PlayerGold>=5000){

numHealthPotions = numHealthPotions + 100;
PlayerGold = PlayerGold - 5000;

}else { input = "100"; }

}





}





}
if (input.equals("2")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zum Nekromanten!");
System.out.println("--------------------------------------------");
System.out.println("Soll ich einen Verbündeten beschwören?");
System.out.println("1. Ja (200 ZerfetzteKörperteileVonRandomGegnern)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();



if (input.equals("1")) {

if (ZerfetzteKörperteileVonRandomGegnern>=200){

ZerfetzteKörperteileVonRandomGegnern = ZerfetzteKörperteileVonRandomGegnern - 200;
Helfer = 15;


}else { input = "100"; }

}




}
if (input.equals("3")) {
for (int i = 0; i < 80; i++) {
System.out.println();
}
System.out.println("Du Gelangst zur bar!");
System.out.println("--------------------------------------------");
System.out.println("Willst du dich vollheilen?");
System.out.println("1. Ja (100)");
System.out.println("2. Zurück in den Dungeon");
input = in.nextLine();


if (input.equals("1")) {

if (PlayerGold>=100){

PlayerGold = PlayerGold - 100;
health = 100;


}else { input = "100"; }

}


}

}
}


if ((Fail)||(Exit)&&(Exit2)) {
break;
}
}
}
for (int i = 0; i < 80; i++) {
System.out.println();
}
if (Fail) {
Score /= 2;

System.out.println("#######################");
System.out.println("# DANKE FÜRS SPIELEN! #");
System.out.println("#######################");
System.out.println();
System.out.println("Dein Score ist " + Score);
System.out.println("Name: ");
for (int i = 0; i < 9; i++) {
System.out.println();
}
String input = in.nextLine();

String name = input;
try {
FileWriter write = new FileWriter("text.txt", true);
PrintWriter text = new PrintWriter(write);
text.println(name + ":");
text.println(Score);
text.println();
text.flush();
write.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
for (int i = 0; i < 100; i++) {
System.out.println();
}
}
}
}
[/Java]
 

Zurück
Oben