Danicron

my practice java rpg1

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