//Pokemon Arena
import java.util.*;
import java.io.*;
import java.awt.geom.*;
//WHAT GOES WHERE NOW???
public class PokemonArena{
private static ArrayList<Pokemon>pokes = new ArrayList<Pokemon>();
private static ArrayList<Pokemon>fakepokes = new ArrayList<Pokemon>();
private static ArrayList <Pokemon> goodPokemon = new ArrayList<Pokemon>();
private static ArrayList <Pokemon> enemyPokemon = new ArrayList<Pokemon>();
private static ArrayList <Attack> attacks = new ArrayList<Attack>();
private static ArrayList <Attack> goodPokemonAttacks = new ArrayList<Attack>();
public static Pokemon currentPokemon; //private or public
public static Pokemon currentEnemy; //private or public
public static int numPokes;
public static int numPokes2;
public static int numPokes3;
public static int turn;
public static boolean isAlive;
public static int userStunPass;
public static int enemyStunPass;
public static double damageEffect;
public static boolean gpDisabled;
public static boolean epDisabled;
//LOADS ALL POKEMON GROUPS & ATTACKS
public static void loadAll () throws IOException{
Scanner pokemonStats = new Scanner(new BufferedReader(new FileReader("pokemon.txt")));
Scanner pokemonStats2 = new Scanner(new BufferedReader(new FileReader("pokemon.txt")));
Scanner pokemonStats3 = new Scanner(new BufferedReader(new FileReader("pokemon.txt")));
numPokes = Integer.parseInt(pokemonStats.nextLine());
for (int i=0; i<numPokes; i++){
pokes.add(new Pokemon(pokemonStats.nextLine()));
}
numPokes2 = Integer.parseInt(pokemonStats2.nextLine());
for (int i=0; i<numPokes2; i++){
fakepokes.add(new Pokemon (pokemonStats2.nextLine()));
}
// numPokes3 = Integer.parseInt(pokemonStats3.nextLine());
// for (int i=0; i<numPokes3; i++){
// fakepokes.add(new Pokemon (pokemonStats3.nextLine()));
// attacks.add(new Attack(pokemonStats3.nextLine()));
// }
}
public static void main (String [] args) throws IOException{
loadAll(); //loads all data from the pokemon.txt file
setUpGame();
setUpBattle();
}
//IMPORTANT PROCEDURES THAT TAKE PLACE AT THE BEGINNING OF THE GAME
public static void setUpGame(){
findGoodPokemon();
findEnemyPokemon();
setTurn();
}
//IMPORTANT PROCEDURES THAT TAKE PLACE BEFORE EACH BATTLE
public static void setUpBattle(){
findCurrentEnemy();
findCurrentPokemon();
manageTurn();
changeTurn(userStunPass, enemyStunPass);
manageTurn();
unableToBattle();
healGoodPokemon();
}
//CREATES GOOD POKEMON GROUP AND ENEMY POKEMON GROUP
public static ArrayList findGoodPokemon (){
for (int i=0; i<numPokes; i++){
System.out.printf("%d)%s\n", i, pokes.get(i).getName());
}
String [] places = {"first", "second", "third", "fourth"};
String [] numbers = {"four", "three", "two", "one"};
for (int i=0; i<4; i++){
System.out.printf("You must choose %s pokemon. \nWhat is the %s pokemon that you choose? Select option by inputting corresponding number.\n", numbers[i], places[i]);
Scanner kb = new Scanner (System.in);
int pos = kb.nextInt();
goodPokemon.add(pokes.get(pos));
pokes.remove(pokes.get(pos));
}
System.out.printf("\nYour Pokemon are:\n");
for (int i=0; i<goodPokemon.size(); i++){
System.out.print(goodPokemon.get(i).getName() + "\n");
}
return goodPokemon;
}
public static ArrayList findEnemyPokemon (){
for (int i=0; i<pokes.size(); i++){
enemyPokemon.add(pokes.get(i));
}
return enemyPokemon;
}
//FINDS CURRENT GOOD POKEMON
public static Pokemon findCurrentPokemon(){
System.out.printf(" Who will battle against this Pokemon? Select option by inputting corresponding number.\n");//, currentEnemy.getName());
for (int i=0; i<goodPokemon.size(); i++){
System.out.println(i + ")" + goodPokemon.get(i).getName());
}
Scanner kb = new Scanner(System.in);
int currentPos = 0;
currentPos = kb.nextInt();
Pokemon currentPokemon = fakepokes.get(currentPos);
currentPokemon = goodPokemon.get(currentPos);
System.out.printf("%s, I choose you!", currentPokemon.getName());
return currentPokemon;
}
//FINDS CURRENT ENEMY
public static Pokemon findCurrentEnemy(){ //inside the bracket is what you put into the method, outside is what the method outputs
int enemyPos = (int)(Math.random()*enemyPokemon.size());
Pokemon currentEnemy = enemyPokemon.get(enemyPos);
System.out.printf("\nThe current enemy is %s", currentEnemy.getName() + ".");
return currentEnemy;
}
//RECHARGES ALL GOOD POKEMON AND CURRENT ENEMY
public static void rechargeAll(){
for (int i=0; i<goodPokemon.size(); i++){
goodPokemon.get(i).recharge(10);
}
}
//HEALS ALL GOOD POKEMON AFTER END OF ROUND
public static void healGoodPokemon(){
for (int i=0; i<goodPokemon.size(); i++){
goodPokemon.get(i).healAll();
goodPokemon.get(i).checkHP();
}
}
//RANDOMLY ASSIGNS THE TURN AT THE BEGINNING OF EACH BATTLE
public static void setTurn(){
//user turn = 1;
//enemy turn = 2;
turn = (int)(Math.random()*2);
userStunPass = 2;
enemyStunPass = 2;
}
//DETERMINES THE TURN AFTER EACH TURN TAKES PLACE
public static void changeTurn(int UserStunPass, int EnemyStunPass){
if (turn == 1){
if (userStunPass == 1){
turn = 1;
}
else if (userStunPass == 2){
turn = 2;
}
}
else if (turn == 2){
if (enemyStunPass == 1){
turn = 2;
}
else if (enemyStunPass == 2){
turn = 1;
}
}
}
//GIVES CONTROL TO THE USER OR COMPUTER DEPENDING ON THE CURRENT TURN
public static void manageTurn(){
if (turn == 1){
System.out.print("It is your turn.");
userMove();
}
else if (turn == 2){
System.out.print("It is the other Pokemon's turn.");
enemyMove();
}
}
//IN CASE OF GAME ENDING
public static void gameOver(){
if (enemyPokemon.size() == 0){
System.out.print("Congratulations, you are now the TRAINER SUPREME! You have beat them all!");
}
if (goodPokemon.size() == 0){
System.out.print("Your Pokemon are no longer able to battle. Please try again!");
}
}
//has to reloop to the very beginning if user loses
//IN CASE OF POKEMON BEING DEAD
public static void unableToBattle(){
for (int i=0; i<goodPokemon.size(); i++){
if (goodPokemon.get(i).checkAlive() == false){
System.out.printf("%s is no longer able to battle!", goodPokemon.get(i).getName());
goodPokemon.remove(goodPokemon.get(i));
}
}
}
//USER CHOOSES WHAT THEY WILL DO ON THEIR TURN
public static void userMove(){
System.out.print("What would you like to do next? Select option by inputting corresponding number.\n1)Atttack 2)Retreat 3)Pass\n");
Scanner kb = new Scanner (System.in);
int nextMove = kb.nextInt();
while (nextMove < 0 || nextMove > 3){
System.out.print("That is NOT a valid option. What would you like to do next? (Select option by inputting number.)");
}
if (nextMove == 1){
attack();
}
else if (nextMove == 2){
retreat();
}
else if (nextMove == 3){
pass();
}
}
//WHAT THE ENEMY POKEMON WILL DO ON THEIR TURN
public static int enemyMove(){
int enemyAttack = (int)((Math.random())*currentEnemy.getNumAttacks());
boolean goodMove = false;
checkEPResistance();
//checks that energyLvl is enough for selected move
while (goodMove == false){
if (currentEnemy.getEnergyLvl() > currentEnemy.getAttacks(enemyAttack).getEnergyCost()){
goodMove = true;
}
else if (currentEnemy.getEnergyLvl() < currentEnemy.getAttacks(enemyAttack).getEnergyCost()){
goodMove = false;
}
if (goodMove == true){
break;
}
}
if (currentEnemy.getAttacks(enemyAttack).getSpecial() == "stun"){
int enemyStunPass = (int)(Math.random()*2);
if (enemyStunPass == 1){
System.out.printf("%s attacks %s with %s!", currentEnemy.getName(), currentPokemon.getName(), currentEnemy.getAttacks(enemyAttack).getAttackName());
currentPokemon.getsHurt((int)(currentEnemy.getAttacks(enemyAttack).getDamage()*damageEffect));
System.out.printf("%s has been stunned by %s and cannot move!", currentEnemy.getName(), currentEnemy.getName());
}
else if (enemyStunPass == 2){
System.out.printf("%s attacks %s with %s!", currentEnemy.getName(), currentPokemon.getName(), currentEnemy.getAttacks(enemyAttack).getAttackName());
currentPokemon.getsHurt((int)(currentEnemy.getAttacks(enemyAttack).getDamage()*damageEffect));
}
}
else if (currentEnemy.getAttacks(enemyAttack).getSpecial() == "wild card"){
int wildCardPass = (int)(Math.random()*2);
if (wildCardPass == 1){
System.out.printf("%s attacks %s with %s!", currentEnemy.getName(), currentPokemon.getName(), currentEnemy.getAttacks(enemyAttack).getAttackName());
currentPokemon.getsHurt((int)(currentEnemy.getAttacks(enemyAttack).getDamage()*damageEffect));
}
else if (wildCardPass == 2){
System.out.printf("%s's Wild Card attack failed!", currentPokemon.getName());
}
}
else if (currentEnemy.getAttacks(enemyAttack).getSpecial() == "wild storm"){
int wildStormPass = (int)(Math.random()*2);
if (wildStormPass == 1){
System.out.printf("%s attacks %s with %s!", currentEnemy.getName(), currentPokemon.getName(), currentEnemy.getAttacks(enemyAttack).getAttackName());
int wildStormNumber = (int)(Math.random());
System.out.printf("It's a Wild Storm! Wild Storm %d", wildStormNumber);
currentPokemon.getsHurt((int)(currentEnemy.getAttacks(enemyAttack).getDamage()*damageEffect)*wildStormNumber);
}
else if (wildStormPass == 2){
System.out.printf("%s's Wild Storm attack failed!", currentPokemon.getName());
}
}
else if (currentEnemy.getAttacks(enemyAttack).getSpecial() == "disable"){
System.out.printf("%s attacks %s with %s!", currentEnemy.getName(), currentPokemon.getName(), currentEnemy.getAttacks(enemyAttack).getAttackName());
System.out.printf("%s has been disabled!", currentPokemon.getName());
gpDisabled = true;
}
else if (currentEnemy.getAttacks(enemyAttack).getSpecial() == "recharge"){
System.out.printf("%s attacks %s with %s!", currentEnemy.getName(), currentPokemon.getName(), currentEnemy.getAttacks(enemyAttack).getAttackName());
currentPokemon.getsHurt((int)(currentEnemy.getAttacks(enemyAttack).getDamage()*damageEffect));
System.out.printf("%s recharges his energy by 20!", currentPokemon.getName());
currentEnemy.recharge(20);
}
return enemyStunPass;
}
//USER'S ATTACK
public static int attack(){
boolean goodMove = false;
//checkGPResistance();
System.out.printf("The attacks of %s are:", currentPokemon.getName());
for (int i=0; i<currentPokemon.getNumAttacks(); i++){
System.out.print(currentPokemon.getAttacks(i).getAttackName());
}
Scanner kb = new Scanner (System.in);
int chosenAttack = 0;
//checks that energyLvl is enough for selected move
while (goodMove == false){
System.out.println("What attack would you like to do? (Select option by inputting number.)");
chosenAttack = kb.nextInt();
if (currentPokemon.getEnergyLvl() >currentPokemon.getAttacks(chosenAttack).getEnergyCost()){
goodMove = true;
}
else if (currentPokemon.getEnergyLvl() < currentPokemon.getAttacks(chosenAttack).getEnergyCost()){
goodMove = false;
System.out.print("You do not have enough energy to do this move! Please pick another attack.");
}
if (goodMove == true){
break;
}
}
if (currentPokemon.getAttacks(chosenAttack).getSpecial() == "stun"){
int userStunPass = (int)(Math.random()*2);
if (userStunPass == 1){
System.out.printf("%s attacks %s with %s!", currentPokemon.getName(), currentEnemy.getName(), currentPokemon.getAttacks(chosenAttack).getAttackName());
currentEnemy.getsHurt(currentPokemon.getAttacks(chosenAttack).getDamage());
System.out.printf("%s has been stunned!", currentEnemy.getName());
}
else if (userStunPass == 2){
System.out.printf("%s attacks %s with %s!", currentPokemon.getName(), currentEnemy.getName(), currentPokemon.getAttacks(chosenAttack).getAttackName());
currentEnemy.getsHurt((int)currentPokemon.getAttacks(chosenAttack).getDamage());
}
}
else if (currentPokemon.getAttacks(chosenAttack).getSpecial() == "wild card"){
int wildCardPass = (int)(Math.random()*2);
if (wildCardPass == 1){
System.out.printf("%s attacks %s with %s!", currentPokemon.getName(), currentEnemy.getName(), currentPokemon.getAttacks(chosenAttack).getAttackName());
currentEnemy.getsHurt((int)currentPokemon.getAttacks(chosenAttack).getDamage());
}
else if (wildCardPass == 2){
System.out.printf("%s's Wild Card attack failed!", currentPokemon.getName());
}
}
else if (currentPokemon.getAttacks(chosenAttack).getSpecial() == "wild storm"){
int wildStormPass = (int)(Math.random()*2);
if (wildStormPass == 1){
System.out.printf("%s attacks %s with %s!", currentPokemon.getName(), currentEnemy.getName(), currentPokemon.getAttacks(chosenAttack).getAttackName());
int wildStormNumber = (int)(Math.random());
System.out.printf("It's a Wild Storm! Wild Storm %d", wildStormNumber);
currentEnemy.getsHurt((int)currentPokemon.getAttacks(chosenAttack).getDamage()*wildStormNumber);
}
else if (wildStormPass == 2){
System.out.printf("%s's Wild Storm attack failed!", currentPokemon.getName());
}
}
else if (currentPokemon.getAttacks(chosenAttack).getSpecial() == "disable"){ //???
System.out.printf("%s attacks %s with %s!", currentPokemon.getName(), currentEnemy.getName(), currentPokemon.getAttacks(chosenAttack).getAttackName());
System.out.printf("%s has been disabled!", currentEnemy.getName());
epDisabled = true;
}
else if (currentPokemon.getAttacks(chosenAttack).getSpecial() == "recharge"){
System.out.printf("%s attacks %s with %s!", currentPokemon.getName(), currentEnemy.getName(), currentPokemon.getAttacks(chosenAttack).getAttackName());
currentEnemy.getsHurt((int)currentPokemon.getAttacks(chosenAttack).getDamage());
System.out.printf("%s recharges his energy by 20!", currentPokemon.getName());
currentPokemon.recharge(20);
}
return userStunPass;
}
//CHECKS IF THE GOOD POKEMON IS RESISTANT OR WEAK AGAINST THE ENEMY POKEMON
public static double checkGPResistance (){
String [] types = {"EARTH", "FIRE", "GRASS", "WATER", "FIGHTING", "ELECTRIC"};
damageEffect = 0;
if (currentPokemon.getType() == currentEnemy.getResistance()){ //checks if good Pokemon's attack damage is halved or not
damageEffect = 0.5;
}
else if (currentPokemon.getType() == currentEnemy.getWeakness()){ //checks if good Pokemon's attack damage is doubled or not
damageEffect = 2;
}
else{
damageEffect = 1;
}
return damageEffect;
}
//CHECKS IF THE ENEMY POKEMON IS RESISTANT OR WEAK AGAINST THE USER'S POKEMON
public static double checkEPResistance (){
String [] types = {"EARTH", "FIRE", "GRASS", "WATER", "FIGHTING", "ELECTRIC"};
damageEffect = 0;
if (currentEnemy.getType() == currentPokemon.getResistance()){ //checks if enemy Pokemon's attack damage is halved or not
damageEffect = 0.5;
}
else if (currentPokemon.getType() == currentEnemy.getWeakness()){ //checks if enemy Pokemon's attack damage is doubled or not
damageEffect = 2;
}
else{
damageEffect = 1;
}
return damageEffect;
}
//USER'S RETREAT
public static void retreat(){
System.out.printf("What Pokemon should replace %s", currentPokemon.getName());
for (int i=0; i<goodPokemon.size(); i++){
if (goodPokemon.get(i).getName() != currentPokemon.getName()){
System.out.println(goodPokemon.get(i).getName());
}
}
Scanner kb = new Scanner (System.in);
int newCurrentPokemon = kb.nextInt();
System.out.printf("%s, return! Go, %s", currentPokemon.getName(), goodPokemon.get(newCurrentPokemon).getName());
currentPokemon = goodPokemon.get(newCurrentPokemon);
}
//USER PASSES TURN
public static void pass(){
System.out.print("You passed your turn.");
}