我不确定为什么会收到此错误。它甚至显示我编译它时,我在文件夹中有类文件但发生此错误。我将提供我的代码,这是我制作的基本游戏。我是Java新手。
package game;
import java.util.Scanner;
import java.util.Random;
public class DungeonGame {
public static void main (String[] args){
// System Objects
Scanner in = new Scanner(System.in);
Random rand = new Random();
// Game Variables
String[] enemies = {"Skeleton", "Zombie", "Warrior", "Assassin"};
int maxEnemyHealth = 75;
int enemyAttackDamage = 25;
// Player Variables
int health = 100; // How much health we have
int attackDamage = 50; // How much damage our player can do
int numHealthPotions = 3; // Number of health pots our player is set with
int healthPotionHealAmount = 30; // Amount a health the pot will raise
int healthPotionDropChance = 50; // Percentage drop
boolean running = true;
GAME:
while (running) {
System.out.println("---------------------------------------------");
int enemyHealth = rand.nextInt(maxEnemyHealth); // Get a random health for enemy (How strong is the enemy?)
String enemy = enemies[rand.nextInt(enemies.length)]; //Set random enemy from array
System.out.println("\t#" + enemy + "appeared! #\n");
while(enemyHealth > 0) {
System.out.println("\tYour HP: " + health);
System.out.println("\t+" + enemy + "'s HP: " + enemyHealth);
System.out.println("\n\tWhat would you like to do?");
System.out.println("\t1. Attack");
System.out.println("\t2. Drink health potion");
System.out.println("\t3. Run!");
String input = in.nextLine();
if(input.equals("1")){
int damageDealt = rand.nextInt(attackDamage);
int damageTaken = rand.nextInt(enemyAttackDamage);
enemyHealth -= damageDealt;
health -= damageTaken;
System.out.println("\t> You strike the " + enemy + "for" + damageDealt + "damage.");
System.out.println("\t> You recieve" + damageTaken + "in retaliation!");
if(health < 1) {
System.out.println(">t You have taken too much damage, you are to weak to go on!");
break;
}
}
else if (input.equals("2")){
if(numHealthPotions > 0) {
health += healthPotionHealAmount;
numHealthPotions--;
System.out.println("\t> You drink a health potion, healing yourself for " + healthPotionHealAmount + "."
+ "\n\t> You now have" + health + "HP."
+ "\n\t> You have" + numHealthPotions + "health potions left.\n");
}
else {
System.out.println("\t> You have no health potions left!! Defeat enemies for a chance to get one. \n");
}
}
else if(input.equals("3")){
System.out.println("\tYou run away from the " + enemy + "!");
continue GAME;
}
else {
System.out.println("\tInvalid Command!");
}
}
if(health < 1) {
System.out.println("You limp out of the dungeon, weak from battle.");
break;
}
System.out.println("---------------------------------------------");
System.out.println(" # " + enemy + " was defeated! #");
System.out.println(" # You have " + health + "HP left. #");
if(rand.nextInt(100) < healthPotionDropChance) {
numHealthPotions++;
System.out.println(" # The " + enemy + "dropped a health potion! #");
System.out.println(" # You now have " + numHealthPotions + "health potion(s). # ");
}
System.out.println("---------------------------------------------");
System.out.println("What would you like to do now?");
System.out.println("1. Continue fighting");
System.out.println("2. Exit game");
String input = in.nextLine();
while(!input.equals("1") && !input.equals("2")) {
System.out.println("invalid Command!");
input = in.nextLine();
}
if(input.equals("1")) {
System.out.println("You continue on your adventure!");
}
else if (input.equals("2")) {
System.out.println("You exit the dengeon, successful from your adventures!");
break;
}
}
}
}