Advertisement
JustACodingStudent

Battle

May 11th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.42 KB | None | 0 0
  1. package battle;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5. public class Battle {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO code application logic here
  9.         Scanner scan = new Scanner(System.in);
  10.         Random numgen = new Random();
  11.         int health1,health2, damage, turns = 0;
  12.         String player1, player2, type1, type2, choice, a;
  13.         boolean winflag;
  14.         System.out.println("Pokemon types:\n1) Fire\n2) Water\n3) Normal\n");
  15.         System.out.print("Player 1: Enter your pokemon name and type: ");
  16.         player1=scan.next();
  17.         type1=scan.next();
  18.            
  19.         System.out.print("Player 2: Enter your pokemon name and type: ");
  20.         player2=scan.next();
  21.         type2=scan.next();
  22.            
  23.        
  24.         health1 = 50 + numgen.nextInt(26);
  25.         health2 = 50 + numgen.nextInt(26);
  26.        
  27.         System.out.println("Players Ready to Battle\n\nFIGHT!!");        
  28.         //loop will execute one attack for each player
  29.         do{
  30.             System.out.println("Player 1, select an option:\n1) THERE IS ONLY FIGHT\n");
  31.             choice = scan.next();
  32.             while(!choice.equalsIgnoreCase("fight"))
  33.             {
  34.                 System.out.print("YOU CAN ONLY FIGHT: ");
  35.                 choice = scan.next();
  36.             }
  37.             a = getAttack(type1);
  38.             damage = 1 + numgen.nextInt(15);
  39.             health2--;
  40.             System.out.println("Player 1's pokemon used " + a + "! Player 2's pokemon took " + damage + " damage!");
  41.             System.out.println("Player 2, select an option:\n1) THERE IS ONLY FIGHT\n");
  42.             choice = scan.next();
  43.             while(!choice.equalsIgnoreCase("fight"))
  44.             {
  45.                 System.out.print("YOU CAN ONLY FIGHT: ");
  46.                 choice = scan.next();
  47.             }
  48.             a = getAttack(type2);
  49.             damage = 1 + numgen.nextInt(15);
  50.             health1--;
  51.             System.out.println("Player 2's pokemon used " + a + "! Player 1's pokemon took " + damage + " damage!");
  52.             if(health1 <= 0)
  53.             {
  54.                 winflag = true;
  55.             }
  56.             else
  57.             {
  58.                 winflag = false;
  59.             }
  60.             turns++;
  61.         }while(health1>0 && health2>0);
  62.        
  63.         if(winflag == true)
  64.         {
  65.             System.out.println("Player 1 has won! It took " + turns + " turns to do so!");
  66.         }
  67.         else
  68.         {
  69.             System.out.println("PLayer 2 has won! It took " + turns + " turns to do so!");
  70.         }
  71.        
  72.     }
  73.    
  74.     public static String getAttack(String type)
  75.     {
  76.         String attack;
  77.         Random generator = new Random();
  78.         int move;
  79.         move=generator.nextInt(3);
  80.         if (type.equalsIgnoreCase("fire"))
  81.         {  
  82.             if(move==0)
  83.                 attack="Flamethrower";
  84.             else if (move ==1)
  85.                 attack="Fireblast";
  86.             else
  87.                 attack="Torch";
  88.         }
  89.         else if(type.equalsIgnoreCase("water"))
  90.         {
  91.             if(move == 0)
  92.                 attack = "Hydro Pump";
  93.             else if(move == 1)
  94.                 attack = "Bubbles";
  95.             else
  96.                 attack = "Water Gun";
  97.         }
  98.         else
  99.         {
  100.             if(move == 0)
  101.                 attack = "Quick Attack";
  102.             else if(move == 1)
  103.                 attack = "Iron Tail";
  104.             else
  105.                 attack = "Scratch";
  106.         }
  107.        
  108.         return (attack);
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement