Question: I'm having trouble running this through a java compiler. What seems to be wrong with it? The error that's showing is from this: error: cannot

I'm having trouble running this through a java compiler.

What seems to be wrong with it?

The error that's showing is from this:

error: cannot find symbol

int damageTaken = rand.nextInt(EnemyAttackDamage);

symbol: variable EnemyAttackDamage

location: class Main

import java.util.Random; import java.util.Scanner;

public class Main { public static void main(String[] args) { //System objects Scanner in = new Scanner(System.in); Random rand = new Random(); //Game Variables String[] enemies = { "Gargoyle", "Ghoul", "Barbarian", "Hobgoblin" }; int maxEnemyHealth = 100; int maxEnemyAttackDamage = 35; //Player Variables int health = 150; int attackDamage = 45; int numHealthPotions = 5; int healthPotionHealAmount = 25; int healthPotionDropChance = 55; //Percentage of drop boolean running = true; System.out.println("Welcome to the Karamja Dungeon!"); GAME: while(running) { System.out.println("----------------------------------------------------"); int enemyHealth = rand.nextInt(maxEnemyHealth); String enemy = enemies[rand.nextInt(enemies.length)]; System.out.println("\t# " + enemy + "appeared! # "); while (enemyHealth > 0) { System.out.println("\tYour HP: " + health); System.out.println("\t" + enemy + "'s HP: " + enemyHealth); System.out.println(" \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're heavily injured, you are too weak to continue fighting!"); break; } } else if(input.equals("2")) { if(numHealthPotions > 0) { health += healthPotionHealAmount; numHealthPotions--; System.out.println("\t> You drank a health potion, healing yourself for " + healthPotionHealAmount + " . " + " \t> You now have" + health + " HP." + " \t> You have " + numHealthPotions + " health potions left. "); } else { System.out.println("\t> You ran out of health potions! Defeat enemies for a chance to get another one! "); } } 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 exit the dungeon to escape, unable to continue."); 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 will be your next move?"); System.out.println("1. Continue fighting."); System.out.println("2. Exit the dungeon."); 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 to advance!"); } else if(input.equals("2")) { System.out.println("You have defeated all the enemies, you exit the dungeon!"); break; } } System.out.println("+++++++++++++++++++++++"); System.out.println("# THANKS FOR PLAYING! :) #"); System.out.println("+++++++++++++++++++++++"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!