/ Published in: Java

Finished :)
by Ben Sauberman
by Ben Sauberman
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package pokemonbattle; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import java.awt.Graphics; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.InputMismatchException; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.JFrame; import javax.swing.JPanel; import java.lang.InterruptedException; /** * * @author bensauberman */ boolean walk = false; URL mainURL = new URL("http://oi63.tinypic.com/2zpip89.jpg"); BufferedImage main = ImageIO.read(mainURL); URL openingURL = new URL ("http://oi65.tinypic.com/2wnbh4n.jpg"); BufferedImage opening = ImageIO.read(openingURL); URL bridgeURL = new URL ("http://oi68.tinypic.com/2vwv7nm.jpg"); BufferedImage bridge = ImageIO.read(bridgeURL); URL closingURL = new URL ("http://oi67.tinypic.com/25kh05c.jpg"); BufferedImage closing = ImageIO.read(closingURL); URL grassURL = new URL ("http://oi65.tinypic.com/123r060.jpg"); BufferedImage grass = ImageIO.read(grassURL); URL waterURL = new URL ("http://oi68.tinypic.com/2hibfao.jpg"); BufferedImage water = ImageIO.read(waterURL); URL hFenceURL = new URL ("http://oi63.tinypic.com/2eao6me.jpg"); BufferedImage horizontalFence = ImageIO.read(hFenceURL); URL vFenceURL = new URL ("http://oi68.tinypic.com/2j3s1sk.jpg"); BufferedImage verticalFence = ImageIO.read(vFenceURL); URL sidewaysBridgeURL = new URL ("http://oi68.tinypic.com/30w9ie8.jpg"); BufferedImage sidewaysBridge = ImageIO.read(sidewaysBridgeURL); URL pokeCenterURL = new URL ("http://oi66.tinypic.com/ip06le.jpg"); BufferedImage pokeCenter = ImageIO.read(pokeCenterURL); URL pokeMartURL = new URL ("http://oi68.tinypic.com/149vazd.jpg"); BufferedImage pokeMart = ImageIO.read(pokeMartURL); URL smallHorizontalFenceURL = new URL ("http://oi64.tinypic.com/30l29vs.jpg"); BufferedImage smallHorizontalFence = ImageIO.read(smallHorizontalFenceURL); URL smallVerticalFenceURL = new URL ("http://oi64.tinypic.com/30l29vs.jpg"); BufferedImage smallVerticalFence = ImageIO.read(smallVerticalFenceURL); URL mainBackWalk1URL = new URL("http://oi66.tinypic.com/2ebwl8w.jpg"); BufferedImage mainBackWalk1 = ImageIO.read(mainBackWalk1URL); URL mainBackWalk2URL = new URL("http://oi67.tinypic.com/96j3wm.jpg"); BufferedImage mainBackWalk2 = ImageIO.read(mainBackWalk2URL); URL mainFrontWalk1URL = new URL("http://oi68.tinypic.com/w0mhqb.jpg"); BufferedImage mainFrontWalk1 = ImageIO.read(mainFrontWalk1URL); URL mainFrontWalk2URL = new URL("http://oi67.tinypic.com/2m7vpsn.jpg"); BufferedImage mainFrontWalk2 = ImageIO.read(mainFrontWalk2URL); URL mainLeftWalk1URL = new URL("http://oi63.tinypic.com/34r7fgy.jpg"); BufferedImage mainLeftWalk1 = ImageIO.read(mainLeftWalk1URL); URL mainLeftWalk2URL = new URL("http://oi66.tinypic.com/207xffm.jpg"); BufferedImage mainLeftWalk2 = ImageIO.read(mainLeftWalk2URL); URL mainRightWalk1URL = new URL("http://oi68.tinypic.com/14dzsr5.jpg"); BufferedImage mainRightWalk1 = ImageIO.read(mainRightWalk1URL); URL mainRightWalk2URL = new URL("http://oi64.tinypic.com/2zjhv11.jpg"); BufferedImage mainRightWalk2 = ImageIO.read(mainRightWalk2URL); Pokemon[] myParty = new Pokemon[6]; Pokemon[] oppParty = new Pokemon[6]; ArrayList<Item> myBag = new ArrayList<Item>(); int stoppedLine = 0; int wins = 0; int losses = 0; int earnings = 0; boolean shiftActivated = false; static int round = 1; boolean hasReadFile = false; boolean displayMain = true; int tD = 0; int x1 = (int)(bridge.getWidth()/2 + 7); int y1 = 720; //-180 is to skip to the end int up = -318+tD; final int left = 15; int right = bridge.getWidth() - 15; int down = 780; ArrayList<Integer> trainerLines = new ArrayList<>(); ArrayList<Boolean> validTrainerLines = new ArrayList<>(); ArrayList<Boolean> isWild = new ArrayList<>(); ArrayList<Trainer> trainers = new ArrayList<>(); { super(); readTrainerFile(); addKeyListener(this); setFocusable(true); setFocusTraversalKeysEnabled(false); for(int y = 1; y <= 25; y++) { trainerLines.add(600-(34*y) - (bridge.getHeight()/2)); validTrainerLines.add(true); } } { if(y1 <= 200) { tD = 500; if(!shiftActivated) { for(int x = 0; x < trainerLines.size(); x++) { int oldLine = trainerLines.get(x); trainerLines.set(x, oldLine+tD); } } shiftActivated = true; } if(y1 > 200) { if(shiftActivated) { tD = 0; for(int x = 0; x < trainerLines.size(); x++) { int oldLine = trainerLines.get(x); trainerLines.set(x, (oldLine-500)); } } shiftActivated = false; } super.paintComponent(g); // call superclass to make panel display correctly g.drawImage(water, 0, 0, this); g.drawImage(water, 0, 400, this); for(int y = 721; y < 1000; y+= grass.getHeight()) { for(int x = 15; x < bridge.getWidth(); x += grass.getWidth()) { g.drawImage(grass, x, y+tD, this); } } g.drawImage(verticalFence, 10, 721+tD, this); g.drawImage(verticalFence, 10, 750+tD, this); g.drawImage(verticalFence, bridge.getWidth(), 721+tD, this); g.drawImage(verticalFence, bridge.getWidth(), 750+tD, this); g.drawImage(horizontalFence, 10, 796+tD, this); g.drawImage(opening, 7, 650+tD, this); g.drawImage(closing, 7, -318+tD, this); for(int y = 1; y <= 28; y++) { g.drawImage(bridge, 7, 708-(34*y) - bridge.getHeight() +tD, this); } boolean trainerIsRight = true; for(int y = 1; y <= 25; y++) { if(trainerIsRight) { g.drawImage(trainers.get(y-1).getPic(), bridge.getWidth() - 15 + trainers.get(y-1).getAddX(), 600-(34*y) - (bridge.getHeight()/2) +tD, this); trainers.get(y-1).setX(bridge.getWidth() - 15 + trainers.get(y-1).getAddX()); trainerIsRight = false; } else { g.drawImage(trainers.get(y-1).getPic(), 15 + trainers.get(y-1).getAddX(), 600-(34*y) - (bridge.getHeight()/2) +tD, this); trainers.get(y-1).setX(15 + trainers.get(y-1).getAddX()); trainerIsRight = true; } } for(int x = 0; x < 5; x++) { g.drawImage(sidewaysBridge, 67+sidewaysBridge.getWidth()*x -8*x, 620 +tD, this); } for(int x = 0; x < 21; x++) { g.drawImage(smallHorizontalFence, 69+8*x, 650+tD, this); } for(int x = 0; x < 3; x++) { g.drawImage(smallVerticalFence, 73, 648 - 10*x + tD, this); } //g.drawImage() g.drawImage(pokeMart, 80, 598+tD, this); g.drawImage(pokeCenter, 150, 590+tD, this); if(displayMain) { g.drawImage(main, x1, y1+tD, this); } } Scanner fr = new Scanner(url.openStream()).useDelimiter(","); while (fr.hasNextLine()) { if(vL.equals("|||,")) { Trainer trainer = new Trainer(picDirectory); trainers.add(trainer); } } } public void checkForBattle(int movement) throws InterruptedException, FileNotFoundException, IOException { z: for(int x = 0; x < trainerLines.size(); x++) { if(y1+tD+movement == trainerLines.get(x) && validTrainerLines.get(x) == true) { int moveCounter = 0; if(x % 2 == 0) { while(trainers.get(x).getX()-10 > x1) { trainers.get(x).addX(-1); moveCounter++; repaint(); } } if(x % 2 != 0) { while(trainers.get(x).getX()+10 < x1) { trainers.get(x).addX(1); moveCounter++; repaint(); } } repaint(); initiateBattle(); validTrainerLines.set(x, false); break z; } } } if(!hasReadFile) { readInitFile(); hasReadFile = true; } setFocusable(false); removeParty(oppParty); stoppedLine = readFile(myParty, oppParty, stoppedLine); int didWin = battle(myParty, oppParty, trainerName, myBag, true); resetParty(myParty); resetParty(oppParty); if(didWin == 1) { reward(myParty, oppParty, myBag); wins++; } else { losses++; } removeParty(oppParty); round++; calcEarnings(true, 0); setFocusable(true); } if(walk) { main = mainLeftWalk1; walk = false; } else { main = mainLeftWalk2; walk = true; } repaint(); if(x1 > 72 && x1 <235 && y1 > 650 && y1 < 683) { right = 235; down = 677; up = 650; } else { right = bridge.getWidth() - 15; down = 780; up = -318+tD; } if(x1-1 > left) { x1 = x1-1; repaint(); try { checkForWild(); } } if(walk) { main = mainRightWalk1; walk = false; } else { main = mainRightWalk2; walk = true; } if(x1 > 50 && x1 <235 && y1 > 650 && y1 < 680) { right = 235; down = 677; up = 650; } else { right = bridge.getWidth() - 15; down = 780; up = -318+tD; } if(x1+1 < right) { x1 = x1+1; repaint(); try { checkForWild(); } } if(walk) { main = mainBackWalk1; walk = false; } else { main = mainBackWalk2; walk = true; } if(x1 > 63 && x1 <235 && y1 > 650 && y1 < 683) { right = 235; down = 677; up = 650; } else { right = bridge.getWidth() - 15; down = 780; up = -318+tD; } if(y1-1 > up) { y1 = y1-1; if(x1 >= 178 && x1 <= 186 && y1 <= 651) { setFocusable(false); displayMain = false; repaint(); displayPokeCenter(); displayMain = true; setFocusable(true); } if(x1 >= 108 && x1 <= 116 && y1 <= 651) { setFocusable(false); displayMain = false; repaint(); displayPokeMart(); displayMain = true; setFocusable(true); } repaint(); try { checkForWild(); try { checkForBattle(1); } if(y1 -1 < -318 + tD) { System.out.println("Congratulations on winning the game! Your final record is " + wins + " - " + losses); } } if(walk) { main = mainFrontWalk1; walk = false; } else { main = mainFrontWalk2; walk = true; } if(x1 > 63 && x1 <235 && y1 > 650 && y1 < 683) { right = 235; down = 677; up = 650; } else { right = bridge.getWidth() - 15; down = 780; up = -318+tD; } if(y1+1 < down) { y1 = y1+1; repaint(); try { checkForWild(); try { checkForBattle(1); } } } @Override } @Override } @Override } if(y1 >= 718 && y1 <= 1000 && x1 >= 15 && x1 <= 72) { if(toHaveWild == 1) { setUpWildPokemon(); } } } setFocusable(false); if(!hasReadFile) { readInitFile(); hasReadFile = true; } int maxLevel = 0; for(int pSlot = 0; pSlot < 6; pSlot++) { if(myParty[pSlot] != null) { if(myParty[pSlot].getLevel() > maxLevel) { maxLevel = myParty[pSlot].getLevel(); } } } level += adder; int HP = level * HPMultiplier + HPAdder; determineWildPokemonTier(level, HP); setFocusable(true); } public void determineWildPokemonTier(int level, int HP) throws FileNotFoundException, IOException, InterruptedException { int tier = 0; randTierNumber = (int)randTierNumber * 100 +1; int moves = 0; randMovesNumber = (int)randMovesNumber * 100 +1; if(level <= 10) { tier = 1; randTierNumber = (int)randTierNumber * 100000 +1; if(randTierNumber == 50000) { tier = 4; } if(randMovesNumber <= 50) { moves = 1; } if(randMovesNumber > 50 && randMovesNumber <= 80) { moves = 2; } if(randMovesNumber > 80 && randMovesNumber <= 95) { moves = 3; } if(randMovesNumber > 95) { moves = 4; } } if(level >= 11 && level <= 20) { if(randTierNumber <= 45) { tier = 1; } if(randTierNumber > 45 && randTierNumber <= 90) { tier = 2; } if(randTierNumber > 90) { tier = 3; } randTierNumber = (int)randTierNumber * 10000 +1; if(randTierNumber == 5000) { tier = 4; } if(randMovesNumber <= 10) { moves = 1; } if(randMovesNumber > 10 && randMovesNumber <= 45) { moves = 2; } if(randMovesNumber > 45 && randMovesNumber <= 85) { moves = 3; } if(randMovesNumber > 85) { moves = 4; } } if(level >= 21 && level <= 30) { if(randTierNumber <= 25) { tier = 1; } if(randTierNumber > 25 && randTierNumber <= 70) { tier = 2; } if(randTierNumber > 70) { tier = 3; } randTierNumber = (int)randTierNumber * 5000 +1; if(randTierNumber == 2500) { tier = 4; } if(randMovesNumber <= 20) { moves = 2; } if(randMovesNumber > 20 && randMovesNumber <= 45) { moves = 3; } if(randMovesNumber > 45) { moves = 4; } } if(level >= 31) { if(randTierNumber <= 25) { tier = 2; } if(randTierNumber > 25) { tier = 3; } randTierNumber = (int)randTierNumber * 1000 +1; if(randTierNumber == 500) { tier = 4; } if(randMovesNumber <= 25) { moves = 3; } if(randMovesNumber > 25) { moves = 4; } } if(tier == 4) { level = 60; } determineWildMovesTier(tier, moves, level, HP); } public void determineWildMovesTier(int tier, int moves, int level, int HP) throws FileNotFoundException, IOException, InterruptedException { ArrayList<Integer> wildMoves = new ArrayList<Integer>(); if(tier == 1) { for(int x = 0; x < moves; x++) { randMovesNumber = (int)(randMovesNumber * 100 +1); if(randMovesNumber <= 70) { wildMoves.add(1); } if(randMovesNumber > 70) { wildMoves.add(2); } } } if(tier == 2) { for(int x = 0; x < moves; x++) { randMovesNumber = (int)(randMovesNumber * 100 +1); if(randMovesNumber <= 30) { wildMoves.add(1); } if(randMovesNumber > 30 && randMovesNumber <= 70) { wildMoves.add(2); } if(randMovesNumber > 70) { wildMoves.add(3); } } } if(tier == 3) { for(int x = 0; x < moves; x++) { randMovesNumber = (int)(randMovesNumber * 100 +1); if(randMovesNumber <= 20) { wildMoves.add(1); } if(randMovesNumber > 20 && randMovesNumber <= 50) { wildMoves.add(2); } if(randMovesNumber > 50) { wildMoves.add(3); } } } if(tier == 4) { for(int x = 0; x < moves; x++) { wildMoves.add(3); } } createWildPokemon(tier, wildMoves, level, HP); } public void createWildPokemon(int tier, ArrayList<Integer> wildMoves, int level, int HP) throws FileNotFoundException, IOException, InterruptedException { boolean foundPokemon = false; ArrayList<String> types = new ArrayList<String>(); Pokemon wildPokemon = null; while(!foundPokemon) { Scanner sc = new Scanner(url.openStream()).useDelimiter(","); if(lineNumber % 2 == 0) { lineNumber++; } for(int i = 0; i < lineNumber; i++) { sc.nextLine(); } line = sc.nextLine(); line = ",".concat(line); Scanner sc2 = new Scanner(line).useDelimiter(","); name = sc2.next(); while(sc2.hasNext()) { if(type != "/" || type != "," || type != "/,") { types.add(type); } else { wildPokemon = new Pokemon(name, HP, level, types.get(0)); foundPokemon = true; } } wildPokemon = new Pokemon(name, HP, level, types.get(0)); foundPokemon = true; } } if(foundPokemon) { createWildMoves(tier, types, wildMoves, wildPokemon); } } public void createWildMoves(int tier, ArrayList<String> types, ArrayList<Integer> wildMoves, Pokemon wildPokemon) throws FileNotFoundException, IOException, InterruptedException { for(int x = 0; x < wildMoves.size(); x++) { ArrayList< String> lines = new ArrayList<String>() ; boolean foundMove = false; int tryCount = 0; Scanner sc = new Scanner(url.openStream()).useDelimiter(","); for(int y = 0; y <= 329; y= y+2) { sc.nextLine(); lines.add(s); } while(!foundMove) { line = lines.get(lineNumber); line = ",".concat(line); Scanner sc2 = new Scanner(line).useDelimiter(","); if(posMoveType.equals(moveType)) { int posTier = sc2.nextInt(); if(tryCount == 2000) { posTier -= 1; wildMoves.set(x, wildMoves.get(x)-1); } if(tryCount == 4000) { posTier += 2; wildMoves.set(x, wildMoves.get(x)+2); } if(tryCount == 6000) { moveType = determineWildMoveType(types); posTier -= 1; wildMoves.set(x, wildMoves.get(x)-1); tryCount = 0; } if(posTier == wildMoves.get(x)) { int PP = sc2.nextInt(); double damageMultiplier = sc2.nextDouble(); int accuracy = sc2.nextInt(); int speed = sc2.nextInt(); Move newMove = new Move(name, PP, damage, accuracy, speed, moveType); wildPokemon.addMove(newMove, x); foundMove = true; } tryCount++; } } } initiateWildBattle(wildPokemon); } public void initiateWildBattle(Pokemon wildPokemon) throws IOException, FileNotFoundException, InterruptedException { if(!hasReadFile) { readInitFile(); } resetParty(oppParty); oppParty[0] = wildPokemon; int result = battle(myParty, oppParty, trainerName, myBag, false); if(result == 1) { calcEarnings(false, wildPokemon.getLevel()); } resetParty(oppParty); } int n = types.size(); double total = 0; for(int i = 0; i < n; i++) { } double magicNum = 100/total; double ogMN = magicNum; double sum = 0; for(int i = 0; i < n; i++) { if(randNum <= magicNum) { return types.get(n - i -1); } else { } } return types.get(0); } // TODO code application logic here PokemonBattle panel = new PokemonBattle(); // window for drawing // when it is closed application.add(panel); application.setSize(260, 1000); // window is 500 pixels wide, 400 high application.setVisible(true); application.setResizable(false); trainerName = "Trainer ".concat(sc.nextLine()); System.out.println("As you progress, the opponents increase in difficulty and your Pokemon gain exp and level up as you defeat enemies. "); System.out.println("After each opponent you defeat you get the option of either taking one of their Pokemon to add to your party"); System.out.println("or receiving a random item. After each battle your Pokemon's moves and HP get restored. "); } for(int x = 0; x < 100; x++) { Item masterBall = new Ball("Master Ball", 100000, 0); Item ultraBall = new Ball("Ultra Ball", 50, 0); Item greatBall = new Ball("Great Ball", 40, 0); Item pokeBall = new Ball("Poke Ball", 30, 0); myBag.add(masterBall); myBag.add(ultraBall); myBag.add(greatBall); myBag.add(pokeBall); } Scanner fr = new Scanner(f).useDelimiter(","); //URL url = new URL("http://m.uploadedit.com/ba3s/1488652275683.txt"); //Scanner fr = new Scanner(url.openStream()).useDelimiter(","); while (fr.hasNextLine()) { if(vL.equals("||")) { fr.nextLine(); addPokemon(info, myParty); } if(vL.equals("|")) { fr.nextLine(); addMove(info, myParty); } if(vL.charAt(0) == ('/')) { fr.nextLine(); } } } public int readFile(Pokemon myParty[], Pokemon oppParty[], int line) throws FileNotFoundException, MalformedURLException, IOException { Scanner fr = new Scanner(url.openStream()).useDelimiter(","); int lineCounter = line; for(int i = 0; i < line; i++) { fr.nextLine(); } while (fr.hasNextLine()) { if(vL.equals("||||")) { fr.nextLine(); lineCounter+=2; addPokemon(info, oppParty); } if(vL.equals("|||")) { fr.nextLine(); lineCounter+=2; addMove(info, oppParty); } if(vL.equals("|||||")) { lineCounter++; stoppedLine = lineCounter; return lineCounter; } if(vL.charAt(0) != ('|') ) { fr.nextLine(); lineCounter++; } } return lineCounter; } public static void printParty(Pokemon party[], boolean showNumbers) { if(showNumbers) { } else { } for(int x = 0; x < 6; x++) { if(party[x] != null) { int spaceCount = 0; if(showNumbers) { spaceCount = (16 - party[x].getName().length()); } else { spaceCount = (14 - party[x].getName().length()); } StringBuilder spaces = new StringBuilder(); for(int y = 0; y < spaceCount; y++) { spaces.append(" "); } if(showNumbers) { } else { } if(party[x].getnHP() >= 100) { } else if(party[x].getnHP() >= 10 && party[x].getnHP() <= 99) { } else { } if(party[x].getLevel() >= 10) { } else { } } } } Scanner fr = new Scanner(info).useDelimiter(","); int pHP = fr.nextInt(); int pLevel = fr.nextInt(); Pokemon newPokemon = new Pokemon(pName, pHP, pLevel, pType); for(int pSlot = 0; pSlot < 6; pSlot++) { if(party[pSlot] == null || party[pSlot].getName().toUpperCase().equals(pName.toUpperCase())){ party[pSlot] = newPokemon; break; } } } Scanner fr = new Scanner(info).useDelimiter(","); int mPP = fr.nextInt(); int mDamage = fr.nextInt(); int mAccuracy = fr.nextInt(); int mSpeed = fr.nextInt(); Move newMove = new Move(mName, mPP, mDamage, mAccuracy, mSpeed, mType); int pSlot = 10; y: for(int x = 0; x < 6; x++) { if(party[x]!= null) { if(party[x].getName().toUpperCase().equals(pName.toUpperCase())) { pSlot = x; break y; } } } if(pSlot == 10) { + "Pokemon it belongs to is not currently in the party."); } boolean freeSpot = false; y: for(int mSlot = 0; mSlot < 4; mSlot++) { if(party[pSlot].getMoves()[mSlot] == null) { party[pSlot].getMoves()[mSlot] = newMove; freeSpot = true; break y; } } //REPLACES MOVE IF ALL 4 SLOTS ARE FILLED if(!freeSpot) { party[pSlot].printMoves(); int mSlot = sc.nextInt(); if(mSlot >= 0 && mSlot <= 3) { party[pSlot].addMove(newMove, mSlot); } else { } } } public int battle(Pokemon myParty[], Pokemon oppParty[], String trainerName, ArrayList<Item> myBag, boolean isTrainer) throws FileNotFoundException, IOException, InterruptedException { if(isTrainer) { int oppPokemonCounter = 0; for(int x = 0; x < 6; x++) { if(oppParty[x] != null) { oppPokemonCounter++; } } } if(!isTrainer) { System.out.println("The pokemon is a level " + oppParty[0].getLevel() + " " + oppParty[0].getName()); } Pokemon myPokemon = pickMyPokemon(myParty, null); Pokemon oppPokemon = pickOppPokemon(oppParty); while(checkForValidPokemon(myParty) && checkForValidPokemon(oppParty)) { printParty(myParty, false); printParty(oppParty, false); Move myMove = null; Move oppMove = null; //MY OPTIONS boolean validMove = false; while(!validMove) { int userChoice = chooseOption(); if(userChoice == 1) { int mSlot = pickMyMove(myPokemon, myParty); if(mSlot == -2) { userChoice = 2; validMove = true; } if(mSlot == -1) { validMove = false; } else { myMove = myPokemon.getMoves()[mSlot]; validMove = true; } } if(userChoice == 2) { Pokemon oldPokemon = myPokemon; myPokemon = pickMyPokemon(myParty, myPokemon); if(oldPokemon.getName() != (myPokemon.getName())) { validMove = true; } } if(userChoice == 3) { if(myBag.size() > 0) { boolean hasBeenUsed = chooseItem(myBag, myParty, oppParty, isTrainer); if(hasBeenUsed) { validMove = true; } } else { } } if(userChoice == 4) { boolean didRun = run(isTrainer); if(didRun) { validMove = true; return 2; } } } //OPPONENTS OPTIONS if(!checkForValidPokemon(oppParty)) { printResult(true); return 1; //WIN } boolean hasMadeTurn = false; while(!hasMadeTurn) { if(checkForValidMove(oppPokemon) == false) { oppPokemon = pickOppPokemon(oppParty); hasMadeTurn = true; } boolean hasPickedValidMove = false; int randomMoveCounter = 0; while(!hasPickedValidMove) { randomMoveCounter++; if(oppPokemon.getMoves()[randomMove] != null) { if(oppPokemon.getMoves()[randomMove].getnPP() > 0) { oppMove = oppPokemon.getMoves()[randomMove]; hasPickedValidMove = true; hasMadeTurn = true; } } if(randomMoveCounter >= 200) { oppPokemon = pickOppPokemon(oppParty); hasMadeTurn = true; hasPickedValidMove = true; } } } int checkFaint = useMoves(myMove, oppMove, myPokemon, oppPokemon, isTrainer); if(checkFaint == 1) { oppPokemon = pickOppPokemon(oppParty); } if(checkFaint == 2) { myPokemon = pickMyPokemon(myParty, null); } } if(!checkForValidPokemon(myParty)) { printResult(false); return 0; //LOSE } return 1; } public static int useMoves(Move myMove, Move oppMove, Pokemon myPokemon, Pokemon oppPokemon, boolean isTrainer) throws FileNotFoundException, IOException, InterruptedException { int myMoveSlot = -1; int oppMoveSlot = -1; boolean checkFaint = false; for(int x = 0; x < 4; x++) { if(myMove != null) { if(myPokemon.getMoves()[x] != null) { if(myMove.getName().toUpperCase().equals(myPokemon.getMoves()[x].getName().toUpperCase())) { myMoveSlot = x; } } } if(oppMove != null) { if(oppPokemon.getMoves()[x] != null) { if(oppMove.getName().toUpperCase().equals(oppPokemon.getMoves()[x].getName().toUpperCase())) { oppMoveSlot = x; } } } } if(myMove == null && oppMove == null) { return 0; } if(myMove != null && oppMove == null) { checkFaint = useMove(myMove, myPokemon, oppPokemon, isTrainer); if(checkFaint) { return 0; } else { return 1; } } if(myMove == null && oppMove != null) { checkFaint = useMove(oppMove, oppPokemon, myPokemon, isTrainer); if(checkFaint) { return 0; } else { return 2; } } if(myMove != null && oppMove != null) { if((myMove.getSpeed() * myPokemon.getLevel()) >= (oppMove.getSpeed() * oppPokemon.getLevel())) { checkFaint = useMove(myMove, myPokemon, oppPokemon, isTrainer); if(checkFaint) { checkFaint = useMove(oppMove, oppPokemon, myPokemon, isTrainer); if(checkFaint) { return 0; } else { return 2; } } else { return 1; } } if(((oppMove.getSpeed() * oppPokemon.getLevel())) > ((myMove.getSpeed()) * myPokemon.getLevel())|| oppMoveSlot == -1) { checkFaint = useMove(oppMove, oppPokemon, myPokemon, isTrainer); if(checkFaint) { checkFaint = useMove(myMove, myPokemon, oppPokemon, isTrainer); if(checkFaint) { return 0; } else { return 1; } } else { return 2; } } } return 0; } public static boolean useMove(Move attMove, Pokemon attPokemon, Pokemon defPokemon, boolean isTrainer) throws FileNotFoundException, IOException, InterruptedException { if(attMove.getAccuracy() > accuracyGen) { boolean isCritical = false; int criticalMultiplier = 1; if(criticalGen <= 5) { isCritical = true; criticalMultiplier = 2; } int HPBeforeAttack = defPokemon.getnHP(); attMove.decnPP(); double effectiveMultiplier = decideEffectiveness(attMove.getType(), defPokemon.getType()); defPokemon.setnHP((int)(attMove.getDamage() * (-effectiveMultiplier) * (criticalMultiplier))); if(defPokemon.getnHP() <= 0) { System.out.println(attPokemon.getName() + " used " + attMove.getName() + " and " + defPokemon.getName() + " fainted."); if(effectiveMultiplier == 0.5) { } if(effectiveMultiplier == 2.0) { } if(criticalMultiplier == 2){ } calcEXP(attPokemon, defPokemon, isTrainer); return false; } else if (effectiveMultiplier == 0) { } else { System.out.println(attPokemon.getName() + " used " + attMove.getName() + " decreasing " + defPokemon.getName() + "'s HP from " + HPBeforeAttack + " to " + defPokemon.getnHP()); if(effectiveMultiplier == 0.5) { } if(effectiveMultiplier == 2.0) { } if(criticalMultiplier == 2){ } return true; } } else { " but the attack missed!"); return true; } return true; } public static Pokemon pickMyPokemon(Pokemon myParty[], Pokemon myPokemon) { if(checkForValidPokemon(myParty) == false) { return null; } printParty(myParty, true); boolean isValid = false; while(!isValid) { printParty(myParty, true); boolean validName = false; for(int x = 0; x < 6; x++) { if(myParty[x] != null) { if(myParty[x].getName().toUpperCase().equals(requested.toUpperCase()) || Integer.parseInt(requested)-1 == x) { validName = true; if(myParty[x].getnHP() <= 0) { + " Choose another Pokemon."); } else if (myPokemon != null){ if(myPokemon.getName().toUpperCase().equals(requested.toUpperCase()) && myPokemon.getnHP() > 0) { return myParty[x]; } } if(myPokemon != null || myPokemon == null) { if(myParty[x].getnHP() > 0) { isValid = true; return myParty[x]; } } } } } if(!validName) { + " Choose another Pokemon."); } } return null; } public static Pokemon pickOppPokemon(Pokemon oppParty[]) { for(int x = 0; x < 6; x++) { if(oppParty[x] != null) { if(oppParty[x].getnHP() > 0) { if(checkForValidMove(oppParty[x])) { return oppParty[x]; } } } } return null; } for(int x = 0; x < 6; x++) { if(party[x] != null && party[x].getnHP() > 0) { return true; } } return false; } for(int x = 0; x < 4; x++) { if(pokemon.getMoves()[x] != null) { if(pokemon.getMoves()[x].getnPP() > 0) { return true; } } } return false; } public static int pickMyMove(Pokemon myPokemon, Pokemon myParty[]) { if(!checkForValidMove(myPokemon)) { return -2; } myPokemon.printMoves(); boolean isValid = false; int requestedMove = -1; while(!isValid) { if(requestedMoveWord.equals("0")) { return -1; } if(((myPokemon.getMoves()[0] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[0].getName().toUpperCase()))) || (requestedMoveWord.equals("1"))) { requestedMove = 1; } if(((myPokemon.getMoves()[1] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[1].getName().toUpperCase()))) || (requestedMoveWord.equals("2"))) { requestedMove = 2; } if(((myPokemon.getMoves()[2] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[2].getName().toUpperCase()))) || (requestedMoveWord.equals("3"))) { requestedMove = 3; } if(((myPokemon.getMoves()[3] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[3].getName().toUpperCase()))) || (requestedMoveWord.equals("4"))) { requestedMove = 4; } if(requestedMove >= 1 && requestedMove <= 4) { if(myPokemon.getMoves()[requestedMove-1] != null) { if(myPokemon.getMoves()[requestedMove-1].getnPP() > 0) { return requestedMove-1; } else { } } else { } } else { } } return -1; } public void printResult(boolean result) { if(result) { } if(!result) { int ogEarnings = earnings; earnings = earnings/2; + " been cut from " + ogEarnings + " to " + earnings); x1 = 182; y1 = 651; main = mainFrontWalk1; } } public static int chooseOption() { int userChoice = 0; boolean isValid = false; while (isValid == false) { try { userChoice = s.nextInt(); } catch(InputMismatchException e) { break; } if(userChoice < 1 || userChoice > 4) { } else { isValid = true; } } return userChoice; } switch(type) { case "Normal": return 0; case "Fire": return 1; case "Water": return 2; case "Electric": return 3; case "Grass": return 4; case "Ice": return 5; case "Fighting": return 6; case "Poison": return 7; case "Ground": return 8; case "Flying": return 9; case "Psychic": return 10; case "Bug": return 11; case "Rock": return 12; case "Ghost": return 13; case "Dragon": return 14; case "Dark": return 15; case "Steel": return 16; } return -1; } public static double decideEffectiveness(String moveTypeWord, String defPokemonTypeWord) throws FileNotFoundException, MalformedURLException, IOException { int moveType = effectivenessNumber(moveTypeWord); int defPokemonType = effectivenessNumber(defPokemonTypeWord); double[][] effectivenessChart = new double[17][17]; Scanner fr2 = new Scanner(url.openStream()).useDelimiter(","); for(int x = 0; x < 17; x++) { for(int y = 0; y < 17; y++) { effectivenessChart[x][y] = fr2.nextDouble(); } fr2.nextLine(); } fr2.close(); return effectivenessChart[moveType][defPokemonType]; } public static void calcEXP(Pokemon attPokemon, Pokemon defPokemon, boolean isTrainer) throws InterruptedException { int previousEXP = attPokemon.getEXP(); int previousMaxEXP = attPokemon.getEXP(); int divider = 1; if(!isTrainer) { divider = 2; } attPokemon.addEXP(((defPokemon.getLevel() * 10)+5) / divider); while(attPokemon.getEXP() >= attPokemon.getMaxEXP()) { attPokemon.incLevel(); attPokemon.setMaxEXP(); attPokemon.setEXP(attPokemon.getEXP() - previousMaxEXP); System.out.println(attPokemon.getName() + " has grown from Level " + (attPokemon.getLevel()-1) + " to Level " + attPokemon.getLevel()); attPokemon.setrHP((int)(attPokemon.getrHP() * .05)); System.out.println(attPokemon.getName() + "'s Max HP has now increased to " + attPokemon.getrHP() + "\n"); for(int x = 0; x < 4; x++) { if(attPokemon.getMoves()[x] != null) { attPokemon.getMoves()[x].setDamage(); System.out.println(attPokemon.getName() + "'s " + attPokemon.getMoves()[x].getName() + " has increased its damage to " + attPokemon.getMoves()[x].getDamage()); } } } System.out.println(attPokemon.getName() + " now has " + attPokemon.getEXP() + " out of " + attPokemon.getMaxEXP() + " EXP to get from " + "Level " + attPokemon.getLevel() + " to Level " + (attPokemon.getLevel()+1)); } public void calcEarnings(boolean isTrainer, int level) { int ogEarnings = earnings; if(isTrainer) { earnings += r * 10 * round; } else { earnings += r * level; } } public static void removeParty(Pokemon party[]) { for(int x = 0; x < 6; x++) { party[x] = null; } } public static void resetParty(Pokemon party[]) { for(int pSlot = 0; pSlot < 6; pSlot++) { if(party[pSlot] != null) { party[pSlot].resetnHP(); for(int mSlot = 0; mSlot < 4; mSlot++) { if(party[pSlot].getMoves()[mSlot] != null) { party[pSlot].getMoves()[mSlot].resetnPP(); } } } } } public static void reward(Pokemon myParty[], Pokemon oppParty[], ArrayList<Item> myBag) { + " an opponent's Pokemon of your choosing or receiving a random item."); printParty(oppParty, false); boolean rewardChosen = false; int userChoice = 0; while(!rewardChosen) { if(userChoiceWord.toUpperCase().equals("Add/Replace Pokemon".toUpperCase())) { userChoice = 1; } if(userChoiceWord.toUpperCase().equals("Receive Random Item".toUpperCase())) { userChoice = 2; } if(userChoiceWord.equals("1")) { userChoice = 1; } if(userChoiceWord.equals("2")) { userChoice = 2; } if(userChoice == 1) { rewardChosen = takeOppPokemon(myParty, oppParty, true); } if(userChoice == 2) { rewardChosen = takeItem(myBag); } } return; } public static boolean takeOppPokemon(Pokemon myParty[], Pokemon oppParty[], boolean isTrainer) { boolean hasTaken = false; while(!hasTaken) { if(!isTrainer) { for(int pSlot = 0; pSlot < 6; pSlot++) { if(myParty[pSlot] == null) { myParty[pSlot] = oppParty[0]; return true; } } return replacePokemon(0, myParty, oppParty); } else { printParty
Comments
