Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package battle;
- import java.util.Random;
- import java.util.Scanner;
- public class Battle {
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner scan = new Scanner(System.in);
- Random numgen = new Random();
- int health1,health2, damage, turns = 0;
- String player1, player2, type1, type2, choice, a;
- boolean winflag;
- System.out.println("Pokemon types:\n1) Fire\n2) Water\n3) Normal\n");
- System.out.print("Player 1: Enter your pokemon name and type: ");
- player1=scan.next();
- type1=scan.next();
- System.out.print("Player 2: Enter your pokemon name and type: ");
- player2=scan.next();
- type2=scan.next();
- health1 = 50 + numgen.nextInt(26);
- health2 = 50 + numgen.nextInt(26);
- System.out.println("Players Ready to Battle\n\nFIGHT!!");
- //loop will execute one attack for each player
- do{
- System.out.println("Player 1, select an option:\n1) THERE IS ONLY FIGHT\n");
- choice = scan.next();
- while(!choice.equalsIgnoreCase("fight"))
- {
- System.out.print("YOU CAN ONLY FIGHT: ");
- choice = scan.next();
- }
- a = getAttack(type1);
- damage = 1 + numgen.nextInt(15);
- health2--;
- System.out.println("Player 1's pokemon used " + a + "! Player 2's pokemon took " + damage + " damage!");
- System.out.println("Player 2, select an option:\n1) THERE IS ONLY FIGHT\n");
- choice = scan.next();
- while(!choice.equalsIgnoreCase("fight"))
- {
- System.out.print("YOU CAN ONLY FIGHT: ");
- choice = scan.next();
- }
- a = getAttack(type2);
- damage = 1 + numgen.nextInt(15);
- health1--;
- System.out.println("Player 2's pokemon used " + a + "! Player 1's pokemon took " + damage + " damage!");
- if(health1 <= 0)
- {
- winflag = true;
- }
- else
- {
- winflag = false;
- }
- turns++;
- }while(health1>0 && health2>0);
- if(winflag == true)
- {
- System.out.println("Player 1 has won! It took " + turns + " turns to do so!");
- }
- else
- {
- System.out.println("PLayer 2 has won! It took " + turns + " turns to do so!");
- }
- }
- public static String getAttack(String type)
- {
- String attack;
- Random generator = new Random();
- int move;
- move=generator.nextInt(3);
- if (type.equalsIgnoreCase("fire"))
- {
- if(move==0)
- attack="Flamethrower";
- else if (move ==1)
- attack="Fireblast";
- else
- attack="Torch";
- }
- else if(type.equalsIgnoreCase("water"))
- {
- if(move == 0)
- attack = "Hydro Pump";
- else if(move == 1)
- attack = "Bubbles";
- else
- attack = "Water Gun";
- }
- else
- {
- if(move == 0)
- attack = "Quick Attack";
- else if(move == 1)
- attack = "Iron Tail";
- else
- attack = "Scratch";
- }
- return (attack);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement