Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- 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 = { "Gromp", "Raptor", "Wolf", "Golem" };
- int maxEnemyHealth = 150; //enemy health
- int enemyAttackDamage = 25; //enemy attack damage
- //Player variables
- int health = 100; //player health
- int attackDamage = 50; //player attack damage
- int numHealthPotions = 3; //number of potions
- int healthPotionHealAmount = 25; //potion heal amount
- int healthPotionDropChance = 33; //percentage
- boolean running = true;
- System.out.println("Welcome to the jungle!");
- GAME:
- while(running) {
- System.out.println("---------------------------------------------------");
- int enemyHealth = rand.nextInt(maxEnemyHealth); //sets enemy's health
- String enemy = enemies[rand.nextInt(enemies.length)]; //chooses 1 of 4 enemies
- System.out.println("\t# " + enemy + " has appeared! #\n"); //enemy appearance
- // # Skeleton had appeared! #
- while(enemyHealth > 0) { //when enemy is alive
- System.out.println("\tYour HP: " + health); //display your HP
- System.out.println("\t" + enemy + "'s HP: " + enemyHealth); //display enemy HP
- System.out.println("\n\tWhat would you like to do?"); //commands
- System.out.println("\t1. Attack");
- System.out.println("\t2. Drink health potion");
- System.out.println("\t3. Run!");
- String input = in.nextLine(); //whatever you respond with
- if(input.equals("1")) { //1
- int damageDealt = rand.nextInt(attackDamage); //damage dealt to enemy
- int damageTaken = rand.nextInt(enemyAttackDamage); //damage taken
- enemyHealth -= damageDealt; //subtracts health
- health -= damageTaken; //subtracts health
- System.out.println("\t> You strike the " + enemy + " for " + damageDealt + " damage."); //explains turn
- System.out.println("\t> You recieve " + damageTaken + " in retaliation!");
- if(health < 1){ //if health is 0
- System.out.println("\t You have taken too much damage, you are too weak to go on!"); //die
- break; //code ends
- }
- }
- else if(input.equals("2")) { //2
- if(numHealthPotions > 0) { //if number of heal potions is greater than 0
- health += healthPotionHealAmount; //uses potion
- numHealthPotions--; //subtracts a potion from inventory
- System.out.println("\t You drink a health potion, healing yourself for " + healthPotionHealAmount + "." //explains turn
- + "\n\t You now have " + health + " HP."
- + "\n\t You have " + numHealthPotions + " health potions left.\n");
- }
- else { //if there are no potions
- System.out.println("\t> You have no health potions left! Defeat enemies for a chance to get one!");
- }
- }
- else if(input.equals("3")) { //3
- System.out.println("\tYou run away from the " + enemy + "!"); //runs from enemy
- continue GAME; //game continues
- }
- else { //if input is other than 1, 2, or 3
- System.out.println("\tInvalid command!"); //invalid command
- }
- }
- if(health < 1) { //if health is less than 1
- System.out.println("You limp out of the dungeon, weak from battle.");
- break; //end of game
- }
- if(health > 1) { //if heath is greater than one
- System.out.println("---------------------------------------------------"); //explanation of what happened
- System.out.println(" # " + enemy + " was defeated! #");
- System.out.println(" # You have " + health + " HP left. #"); //current health
- if(rand.nextInt(100) < healthPotionDropChance) { //health potion drop chance
- numHealthPotions++; //adds one potion
- System.out.println(" # The " + enemy + " dropped a health potion! # "); //explanation
- System.out.println(" # You have " + numHealthPotions + " health potion(s). #");
- }
- System.out.println("---------------------------------------------------"); //what would you like to do
- System.out.println("What would you like to do now?");
- System.out.println("1. Continue fighting");
- System.out.println("2. Exit dungeon");
- String input = in.nextLine();
- while(!input.equals("1") && !input.equals("2")) { //if input is both = invalid
- System.out.println("Invalid Command!");
- input = in.nextLine(); //retry
- }
- if(input.equals("1")) { //continues adventure
- System.out.println("You continue on your adventure!");
- }
- else if(input.equals("2")) { //exits dungeon
- System.out.println("You exit the dungeon, successful from your adventures!");
- break; //end of game
- }
- }
- }
- System.out.println("#######################"); //GG
- System.out.println("# THANKS FOR PLAYING! #"); //GG
- System.out.println("#######################"); //GG
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement