Question: Hello: I have the code for a text adventure game. I was looking for improvements on my code and was wondering how I could include

Hello: I have the code for a text adventure game. I was looking for improvements on my code and was wondering how I could include classes to make it easier to manage:
package pkgfinal.project;
import java.util.Random;
import java.util.Scanner;
public class FinalProject {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
Random rand = new Random();
//Requirement 6. Array
String[] enemies ={ "Psycho", "Skag", "Bruiser", "Bandit", "Rakk" };
//Requirement: Values and Variables
//Requirement: Proper casing
//Requirement: Methods
int maxEnemyHealth =100;
int maxEnemyDamage =25;
int health =100;
int attackDamage =25;
int numHealthPotion =2;
int healthPotHealAmount =25;
int healthPotDropChance =50;
boolean running = true;
System.out.println("Welcome to the Borderlands, Vault Hunter!");
GAME:
//Requirement: Loops
while (running){
System.out.println("-------------------------------------------");
int enemyHealth = rand.nextInt(maxEnemyHealth);
String enemy = enemies[rand.nextInt(enemies.length)];
System.out.println("\t# "+ enemy +" appeared! #
");
//Requirement: Loops
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. Shoot");
System.out.println("\t2. Use health Syringe");
System.out.println("\t3. Flee!");
//Requirement: Selections
String input = in.nextLine();
if (input.equals("1")){
int damageDealt = rand.nextInt(attackDamage);
int damageTaken = rand.nextInt(maxEnemyDamage);
enemyHealth -= damageDealt;
health -= damageTaken;
System.out.println("\t> You hit the" + enemy + "for" + damageDealt + "damage.");
System.out.println("\t> You were hit for:" + damageTaken);
//Requirement: Selections
if (health <1){
System.out.println("\t> You cannot continue the fight, Vault Hunter");
break;
}
} else if (input.equals("2")){
if (numHealthPotion >0){
health += healthPotHealAmount;
numHealthPotion--;
System.out.println("\t> You took a health syringe, healing for "+ healthPotHealAmount +"."
+"
\t> You now have" + health +" HP."
+"
\t> You have "+ numHealthPotion + "Health syringe's left.
");
} else {
System.out.println("\t> You have no health syringe's left. Shoot enemies for a chance of health!");
}
} else if (input.equals("3")){
System.out.println("\tYou ran away from the fight!");
continue GAME;
} else {
System.out.println("\tInvalid Command!");
}
}
if (health <1){
System.out.println("You fight for your life, weak from combat.");
break;
}
System.out.println("-----------------------------------------------");
System.out.println("#"+ enemy + "was killed! #");
System.out.println("# You have" + health +"HP left.");
if (rand.nextInt(100)> healthPotDropChance){
numHealthPotion++;
System.out.println("# The "+ enemy + "dropped a health syringe! # ");
System.out.println("# You now have "+ numHealthPotion +" health syringe(s) # ");
}
System.out.println("-----------------------------------------------");
System.out.println("What action will you take?");
System.out.println("1.Continue the fight?");
System.out.println("2.Leave the fight");
String input = in.nextLine();
//Requirement: Loops
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 with your fight!");
} else if (input.equals("2")){
System.out.println("You leave Pandora Successful.");
break;

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 Programming Questions!