Advertisement
Danicron

javapractice2

Jul 4th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.31 KB | None | 0 0
  1. package javapractice1;
  2.  
  3.  
  4. import java.util.Scanner;
  5. import java.util.Random;
  6.  
  7.  
  8.  
  9.  
  10. public class JavaPractice1 {
  11.      static int BaseEXP;
  12.      static String PlayableCharacterName;
  13.      static int PlayerLevel = 1;
  14.      static int GP = 1;
  15.     private static final int[] LEVEL_REQUIREMENTS = new int[] {60, 200, 400, 1000, 2000};
  16.  
  17.      
  18.      
  19.     public static void main(String[] args) {
  20.         //System objects
  21.         Scanner in;
  22.         in = new Scanner(System.in);
  23.          Random rand ;
  24.          rand = new Random();  
  25.        
  26.        
  27.                
  28.         int health = 300;
  29.          int attackDamage = 50;
  30.          int numHealthPotions = 3;
  31.          int healthPotionHealAmount = 50;
  32.          int healthPotionDropChance = 20;
  33.          
  34.          String[] enemies = {"Elf", "Dwarf", "Halfling", "Man", "Giant", "Goblin", "Orc"};
  35.          int maxEnemyHealth = 250;
  36.          int enemyAttackDamage = 30;
  37.          int expGain = 1;
  38.          int GainGP = rand.nextInt(40);
  39.          expGain = expGain += rand.nextInt(40);
  40.          
  41.          boolean running = true;
  42.          
  43.          System.out.println(" Welcome Back Comrades... ");
  44.          System.out.println("\t>> What is your name?");
  45.             PlayableCharacterName = in.nextLine();
  46.          System.out.println(">> Its time to start your journey " + PlayableCharacterName + "...");
  47.            
  48.          GAME:
  49.          while(running) {
  50.          if (BaseEXP >= LEVEL_REQUIREMENTS[PlayerLevel - 1]) {
  51.                 PlayerLevel++;
  52.                 }
  53.          else if (BaseEXP !LEVEL_REQUIREMENTS[PlayerLevel - 1])
  54.              System.out.println("--------------------------------------------");
  55.              
  56.          int enemyHealth = rand.nextInt(maxEnemyHealth);
  57.          String enemy = enemies[rand.nextInt(enemies.length)];
  58.          System.out.println("\t# " + enemy + " Has Appeared! #\n");
  59.          
  60.          while(enemyHealth > 0) {
  61.              System.out.println("\t Your HP " + health);
  62.              System.out.println("\t" + enemy + "'s HP: " + enemyHealth);
  63.              System.out.println("\n\t What would you like to do?");
  64.              System.out.println("\t1. Attack");
  65.              System.out.println("\t2. Drink Potion");
  66.              System.out.println("\t3. Flee");
  67.            
  68.              String input = in.nextLine();
  69.              if(input.equals("1")) {
  70.                  int damageDealt = rand.nextInt(attackDamage);
  71.                  int damageTaken = rand.nextInt(enemyAttackDamage);
  72.                  
  73.                  enemyHealth -= damageDealt;
  74.                  health -= damageTaken;
  75.                  
  76.                  System.out.println("\t> You hit the " + enemy + " for " + damageDealt + " damage ");
  77.                  System.out.println("\t> You were hit for " + damageTaken + " in response ");
  78.                          
  79.                  if(health < 1) {
  80.                      System.out.println(" You have recieved a killing blow! ");
  81.                      break;
  82.                  }
  83.              }
  84.         else if(input.equals("2")) {
  85.           if(numHealthPotions > 0) {
  86.             health += healthPotionHealAmount;
  87.             numHealthPotions--;
  88.             System.out.println("\t You drink a Health Potion, you are healed for " + healthPotionHealAmount + "."
  89.                              + "\n\t> You now have" + health + " HP "
  90.                              + "\n\t> You have " + numHealthPotions + " Health potions left.\n ");
  91.                  }
  92.                  else {
  93.                      System.out.println("\t> You have no Health Potions left! Defeat some enemies for a chance to get more!");
  94.                  }
  95.              }
  96.              else if(input.equals("3")) {
  97.                  System.out.println("\t> You successfully escaped from " + enemy + " ! ");
  98.                  continue GAME;
  99.             }
  100.              else {
  101.                  System.out.println("\t Invalid Action");
  102.              }
  103.          
  104.          }
  105.          if (health < 1){
  106.              System.out.println (" You iz Dedded, Well done you Muppet....");
  107.              break;
  108.          }
  109.              System.out.println("--------------------------------------------");
  110.              System.out.println(" # " + enemy + " was defeated!! #");
  111.              System.out.println(" # You have" + health + " HP left. #");
  112.             BaseEXP += expGain;
  113.              
  114.          
  115.              {
  116.          }    
  117.              System.out.println("# You have gained " + expGain + "EXP" +
  118.                      "\n You now have " + BaseEXP + "EXP!" );
  119.              System.out.println("You have gained a level!");
  120.              System.out.println("You are now Level " + PlayerLevel + "!");
  121.              
  122.              
  123.             GP = GP += GainGP;
  124.              
  125.             System.out.println("You have gained " + GainGP + " GP from " + enemy);
  126.             System.out.println("You now have " + GP + "GP.");
  127.          
  128.    
  129.              if (rand.nextInt(100) < healthPotionDropChance) {
  130.                  numHealthPotions++;
  131.                  System.out.println("You found a Health Potion from corpse of " + enemy + "#" );
  132.                  System.out.println("You now have " + numHealthPotions + "Health Potions left. #");
  133.              
  134.                 System.out.println("--------------------------------------------");
  135.              System.out.println("What would you like to do now?");
  136.              System.out.println("1. Continue Battling");
  137.              System.out.println("2. Leave ");
  138.              System.out.println("3. Shop");
  139.              }
  140.              String input = in.nextLine();
  141.              
  142.              
  143.              while(!input.equals("1") && (!input.equals("2") && (input.equals("3")))) {
  144.                  System.out.println("Invalid");
  145.                  input = in.nextLine();
  146.              }
  147.              
  148.              if(input.equals ("1")) {
  149.                  System.out.println("Hi Ho, Hi Ho, Adventuring we goooo!!!!");
  150.              }            
  151.             else if(input.equals ("2"))  {
  152.                 System.out.println("Live to fight another day...");
  153.                 break;
  154.             }
  155.                
  156.    
  157.            
  158.  
  159.          }
  160.          
  161.          System.out.println("###############");
  162.          System.out.println("Thank you come again!!");
  163.          System.out.println("###############");
  164.     }
  165.          }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement