Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.73 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class PJ_Battle{
  4.     /****************************************Variables****************************************/
  5.     //Base Variables
  6.     public static Scanner scan = new Scanner(System.in);
  7.     public static Random rand = new Random();
  8.     public static int pokemonNum = 4;
  9.     public static int moveNum = 2;
  10.     public static int n = 0;
  11.     //Title
  12.     public static String TITLE = "Pokemon Java Battle System";
  13.     //User Stats
  14.     public static int cLVL = 5;
  15.     public static int hp = 1;
  16.     public static int cAtk;
  17.     public static int cDef;
  18.     public static int exp = 0;
  19.     //Enemy Stats
  20.     public static int elvl;
  21.     public static int enemy;
  22.     public static int eHP = 1;
  23.     public static int eAtk;
  24.     public static int eDef;
  25.     //Other Stuff
  26.     public static String pokemonChoice;
  27.     public static int pChoice;
  28.     public static int mChoice;
  29.     public static int dmg;
  30.     public static int gain;
  31.     public final static String wS = "   ";
  32.     //Arrays
  33.     public static String[][] pokemon = new String[pokemonNum][4];
  34.     public static String[][] moves = new String[pokemonNum][moveNum];
  35.     public static int[] lvl = new int[100];
  36.     public static String[] statements = new String[100];
  37.    
  38.     /****************************************Load Game****************************************/
  39.     public static void main(String[] args) {       
  40.         /****************************************Data****************************************/
  41.         //Levels
  42.         lvl[n++] = 0;
  43.         lvl[n++] = 0;
  44.         lvl[n++] = 0;
  45.         lvl[n++] = 0;
  46.         lvl[n++] = 50;
  47.         lvl[n++] = 150;
  48.         lvl[n++] = 250;
  49.        
  50.         //Pokemon
  51.         /*Template:
  52.           pokemon[INDEX][0] = "Name";
  53.           pokemon[INDEX][1] = "Heath";
  54.           pokemon[INDEX][2] = "Attack";
  55.           pokemon[INDEX][3] = "Defense";
  56.         */
  57.         //Pikachu
  58.         pokemon[0][0] = "Pikachu";
  59.         pokemon[0][1] = "19";
  60.         pokemon[0][2] = "10";
  61.         pokemon[0][3] = "7";
  62.         //Charmander
  63.         pokemon[1][0] = "Charmander";
  64.         pokemon[1][1] = "20";
  65.         pokemon[1][2] = "11";
  66.         pokemon[1][3] = "5";
  67.         //Squirtle
  68.         pokemon[2][0] = "Squirtle";
  69.         pokemon[2][1] = "18";
  70.         pokemon[2][2] = "8";
  71.         pokemon[2][3] = "8";
  72.         //Bulbasuar
  73.         pokemon[3][0] = "Bulbasuar";
  74.         pokemon[3][1] = "22";
  75.         pokemon[3][2] = "7";
  76.         pokemon[3][3] = "9";
  77.        
  78.         //Moves
  79.         moves[0][0] = "Tackle";
  80.         moves[0][1] = "Growl";
  81.         moves[1][0] = "Scratch";
  82.         moves[1][1] = "Growl";
  83.         moves[2][0] = "Tackle";
  84.         moves[2][1] = "Tail Whip";
  85.         moves[3][0] = "Tackle";
  86.         moves[3][1] = "Growl";
  87.        
  88.         /****************************************Begin Game****************************************/
  89.         System.out.println("Welcome to " + TITLE);
  90.         System.out.println("Available Pokemon:");
  91.         for(int x=0;x<pokemon.length;x++){
  92.             System.out.println(x+1 + ") " + pokemon[x][0]);
  93.         }
  94.         System.out.print("Choose a pokemon: ");
  95.         //Prompt for pokemon choice.
  96.         pChoice = scan.nextInt() - 1;
  97.         pokemonChoice = pokemon[0][pChoice];
  98.        
  99.         //Print chosen pokemon.
  100.         System.out.println("\nYou chose " + pokemonChoice + ".\n");
  101.        
  102.         //Begin Gameplay
  103.         while(true){
  104.             battle();
  105.         }
  106.     }
  107.    
  108.     /****************************************Battle****************************************/
  109.     public static void battle(){
  110.             enemy = rand.nextInt(pokemonNum);
  111.             hp = Integer.parseInt(pokemon[pChoice][1]) + (cLVL-4 * 2);
  112.             cAtk = Integer.parseInt(pokemon[pChoice][2]) + (cLVL-4 * 2);
  113.             cDef = Integer.parseInt(pokemon[pChoice][3]) + (cLVL-4 * 2);
  114.             eHP = Integer.parseInt(pokemon[enemy][1]) + (cLVL-4 * 2);
  115.             eAtk = Integer.parseInt(pokemon[enemy][2]) + (cLVL-4 * 2);
  116.             eDef = Integer.parseInt(pokemon[enemy][2]) + (cLVL-4 * 2);
  117.             initPrintStats(enemy);
  118.     }
  119.    
  120.     /****************************************Attack****************************************/
  121.     public static void attack(int enemy){
  122.         System.out.print("Choose A Move: ");
  123.         mChoice = scan.nextInt();
  124.         attackCalc(mChoice, enemy);
  125.     }
  126.    
  127.     public static void attackCalc(int move, int enemy){
  128.         //Calculate Damage - You.
  129.         boolean miss = rand.nextInt(100)<15?true:false;
  130.         boolean evade = rand.nextInt(100)<10?true:false;
  131.         if(miss==false && evade==false){
  132.             dmg = ((((2*cLVL/5+2)*cAtk*cAtk/eDef)/ 50) + 2)*rand.nextInt(5);;
  133.             if(dmg<=0) dmg = 4;
  134.             eHP = eHP - dmg<0?0:eHP-dmg;
  135.             //Print Outcome
  136.             System.out.println("\nYou attack the foe's " + pokemon[enemy][0] + " for " + dmg + " damage.");
  137.            
  138.             System.out.println();
  139.            
  140.             printStats(enemy);
  141.         }
  142.         else if(miss==true){
  143.             System.out.println("\nYour attack missed.");
  144.            
  145.             System.out.println();
  146.            
  147.             printStats(enemy);
  148.         }
  149.         else{
  150.             System.out.println("\nThe foe evaded your attack.");
  151.            
  152.             System.out.println();
  153.            
  154.             printStats(enemy);
  155.         }
  156.     }
  157.    
  158.     public static void eCalc(int enemy){
  159.         boolean miss = rand.nextInt(100)<15?true:false;
  160.         boolean evade = rand.nextInt(100)<10?true:false;
  161.         if(miss==false && evade==false){
  162.             dmg = ((((2*cLVL/5+2)*eAtk*eAtk/cDef)/ 50) + 2)*rand.nextInt(5);;
  163.             if(dmg<=0) dmg = 4;
  164.             hp = hp - dmg<0?0:hp-dmg;
  165.             //Print Outcome
  166.             System.out.println("\nThe foe's " + pokemon[enemy][0] + " attacks you for " + dmg + " damage.");
  167.            
  168.             System.out.println();
  169.            
  170.             printStats(enemy);
  171.         }
  172.         else if(miss==true){
  173.             System.out.println("\nYour attack missed.");
  174.            
  175.             System.out.println();
  176.            
  177.             printStats(enemy);
  178.         }
  179.         else{
  180.             System.out.println("\nThe foe evaded your attack.");
  181.            
  182.             System.out.println();
  183.            
  184.             printStats(enemy);
  185.         }
  186.     }
  187.    
  188.     /****************************************Stats****************************************/
  189.     public static void initPrintStats(int enemy){
  190.         //User Pokemon
  191.         System.out.print("Pokemon: " + pokemonChoice);
  192.         System.out.print(wS + "HP: " + hp);
  193.         System.out.print(wS + "Level: " + cLVL);
  194.         System.out.print(wS + "Experience: " + exp + "/" + lvl[cLVL-1]);
  195.         System.out.println("\nMoves:");
  196.         for(int x=0;x<moves[pChoice].length;x++){
  197.             System.out.println(x + 1 + ") " + moves[pChoice][x]);
  198.         }
  199.        
  200.         System.out.println();
  201.        
  202.         //Enemy Pokemon
  203.         //Calculate Level
  204.         boolean lvlR = rand.nextInt(100)>50?true:false;
  205.         //Print enemy stats
  206.         System.out.print("Opponent: " + pokemon[enemy][0]);
  207.         if(lvlR==true){
  208.             eHP -= rand.nextInt(5);
  209.             System.out.print(wS + "HP: " + eHP);
  210.             elvl = cLVL - rand.nextInt(3);
  211.             System.out.print(wS + "Level:" + elvl);
  212.             eAtk += rand.nextInt(elvl);
  213.             eDef += rand.nextInt(elvl);
  214.         }
  215.         else{
  216.             eHP += rand.nextInt(5);
  217.             System.out.print(wS + "HP: " + eHP);
  218.             elvl = cLVL + rand.nextInt(3);
  219.             System.out.print(wS + "Level:" + elvl);
  220.             eAtk -= rand.nextInt(elvl);
  221.             eDef -= rand.nextInt(elvl);
  222.         }
  223.        
  224.         System.out.println();
  225.        
  226.         attack(enemy);
  227.     }
  228.    
  229.     public static void printStats(int enemy){
  230.         //User Pokemon
  231.         System.out.print("Pokemon: " + pokemonChoice);
  232.         System.out.print(wS + "HP: " + hp);
  233.         System.out.print(wS + "Level: " + cLVL);
  234.         System.out.println(wS + "Experience: " + exp + "/" + lvl[cLVL-1]);
  235.         System.out.println("Moves:");
  236.         for(int x=0;x<moves[pChoice].length;x++){
  237.             System.out.println(x + 1 + ") " + moves[pChoice][x]);
  238.         }
  239.        
  240.         System.out.println();
  241.        
  242.         //Enemy Pokemon
  243.         //Print enemy stats
  244.         System.out.print("Oponent: " + pokemon[enemy][0]);
  245.         System.out.print(wS + "HP: " + eHP);
  246.         System.out.print(wS + "Level:" + elvl);
  247.    
  248.         if(eHP<=0){
  249.             System.out.println("\n\nFoe " + pokemon[enemy][0] + " fainted.\n");
  250.             exp(enemy);
  251.             System.out.println(pokemonChoice + " gained " + gain + " experience.\n");
  252.             scan.nextLine();
  253.             battle();
  254.         }
  255.         else{
  256.             System.out.println();
  257.             attack(enemy);
  258.         }
  259.     }
  260.    
  261.     /****************************************Levels and EXP****************************************/
  262.     public static void exp(int enemy){
  263.         gain = cLVL*rand.nextInt(elvl) + ((Integer.parseInt(pokemon[enemy][2]) + Integer.parseInt(pokemon[enemy][2])/2));
  264.         if(gain<=0)gain = Integer.parseInt(pokemon[enemy][2]);
  265.         exp+=gain;
  266.     }
  267.    
  268.     public static void level(int leftOver){
  269.        
  270.     }
  271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement