Posted By

bsauberman on 02/20/17


Tagged


Versions (?)

Pokemon Battle Simulator


 / Published in: Java
 

Finished :) by Ben Sauberman

  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package pokemonbattle;
  7.  
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.util.ArrayList;
  11. import java.util.Scanner;
  12.  
  13. import java.awt.Graphics;
  14. import java.awt.Color;
  15. import java.awt.Font;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.awt.event.KeyEvent;
  19. import java.awt.event.KeyListener;
  20. import java.awt.image.BufferedImage;
  21. import java.io.IOException;
  22. import java.net.MalformedURLException;
  23. import java.net.URL;
  24. import java.net.URLConnection;
  25. import java.util.InputMismatchException;
  26. import java.util.logging.Level;
  27. import java.util.logging.Logger;
  28. import javax.imageio.ImageIO;
  29. import javax.swing.JFrame;
  30. import javax.swing.JPanel;
  31. import java.lang.InterruptedException;
  32. /**
  33.  *
  34.  * @author bensauberman
  35.  */
  36. public class PokemonBattle extends JPanel implements ActionListener, KeyListener {
  37. boolean walk = false;
  38. URL mainURL = new URL("http://oi63.tinypic.com/2zpip89.jpg"); BufferedImage main = ImageIO.read(mainURL);
  39. URL openingURL = new URL ("http://oi65.tinypic.com/2wnbh4n.jpg"); BufferedImage opening = ImageIO.read(openingURL);
  40. URL bridgeURL = new URL ("http://oi68.tinypic.com/2vwv7nm.jpg"); BufferedImage bridge = ImageIO.read(bridgeURL);
  41. URL closingURL = new URL ("http://oi67.tinypic.com/25kh05c.jpg"); BufferedImage closing = ImageIO.read(closingURL);
  42. URL grassURL = new URL ("http://oi65.tinypic.com/123r060.jpg"); BufferedImage grass = ImageIO.read(grassURL);
  43. URL waterURL = new URL ("http://oi68.tinypic.com/2hibfao.jpg"); BufferedImage water = ImageIO.read(waterURL);
  44. URL hFenceURL = new URL ("http://oi63.tinypic.com/2eao6me.jpg"); BufferedImage horizontalFence = ImageIO.read(hFenceURL);
  45. URL vFenceURL = new URL ("http://oi68.tinypic.com/2j3s1sk.jpg"); BufferedImage verticalFence = ImageIO.read(vFenceURL);
  46. URL sidewaysBridgeURL = new URL ("http://oi68.tinypic.com/30w9ie8.jpg"); BufferedImage sidewaysBridge = ImageIO.read(sidewaysBridgeURL);
  47. URL pokeCenterURL = new URL ("http://oi66.tinypic.com/ip06le.jpg"); BufferedImage pokeCenter = ImageIO.read(pokeCenterURL);
  48. URL pokeMartURL = new URL ("http://oi68.tinypic.com/149vazd.jpg"); BufferedImage pokeMart = ImageIO.read(pokeMartURL);
  49. URL smallHorizontalFenceURL = new URL ("http://oi64.tinypic.com/30l29vs.jpg"); BufferedImage smallHorizontalFence = ImageIO.read(smallHorizontalFenceURL);
  50. URL smallVerticalFenceURL = new URL ("http://oi64.tinypic.com/30l29vs.jpg"); BufferedImage smallVerticalFence = ImageIO.read(smallVerticalFenceURL);
  51.  
  52. URL mainBackWalk1URL = new URL("http://oi66.tinypic.com/2ebwl8w.jpg"); BufferedImage mainBackWalk1 = ImageIO.read(mainBackWalk1URL);
  53. URL mainBackWalk2URL = new URL("http://oi67.tinypic.com/96j3wm.jpg"); BufferedImage mainBackWalk2 = ImageIO.read(mainBackWalk2URL);
  54. URL mainFrontWalk1URL = new URL("http://oi68.tinypic.com/w0mhqb.jpg"); BufferedImage mainFrontWalk1 = ImageIO.read(mainFrontWalk1URL);
  55. URL mainFrontWalk2URL = new URL("http://oi67.tinypic.com/2m7vpsn.jpg"); BufferedImage mainFrontWalk2 = ImageIO.read(mainFrontWalk2URL);
  56. URL mainLeftWalk1URL = new URL("http://oi63.tinypic.com/34r7fgy.jpg"); BufferedImage mainLeftWalk1 = ImageIO.read(mainLeftWalk1URL);
  57. URL mainLeftWalk2URL = new URL("http://oi66.tinypic.com/207xffm.jpg"); BufferedImage mainLeftWalk2 = ImageIO.read(mainLeftWalk2URL);
  58. URL mainRightWalk1URL = new URL("http://oi68.tinypic.com/14dzsr5.jpg"); BufferedImage mainRightWalk1 = ImageIO.read(mainRightWalk1URL);
  59. URL mainRightWalk2URL = new URL("http://oi64.tinypic.com/2zjhv11.jpg"); BufferedImage mainRightWalk2 = ImageIO.read(mainRightWalk2URL);
  60.  
  61. Pokemon[] myParty = new Pokemon[6];
  62. Pokemon[] oppParty = new Pokemon[6];
  63. ArrayList<Item> myBag = new ArrayList<Item>();
  64.  
  65. int stoppedLine = 0;
  66. int wins = 0;
  67. int losses = 0;
  68.  
  69. int earnings = 0;
  70.  
  71. boolean shiftActivated = false;
  72. static int round = 1;
  73. static String trainerName = "";
  74.  
  75. boolean hasReadFile = false;
  76. boolean displayMain = true;
  77.  
  78. int tD = 0;
  79.  
  80. int x1 = (int)(bridge.getWidth()/2 + 7);
  81. int y1 = 720; //-180 is to skip to the end
  82.  
  83. int up = -318+tD;
  84. final int left = 15;
  85. int right = bridge.getWidth() - 15;
  86. int down = 780;
  87. ArrayList<Integer> trainerLines = new ArrayList<>();
  88. ArrayList<Boolean> validTrainerLines = new ArrayList<>();
  89. ArrayList<Boolean> isWild = new ArrayList<>();
  90. ArrayList<Trainer> trainers = new ArrayList<>();
  91.  
  92. public PokemonBattle() throws IOException // set up graphics window
  93. {
  94. super();
  95. readTrainerFile();
  96.  
  97. setBackground(Color.WHITE);
  98. addKeyListener(this);
  99. setFocusable(true);
  100. setFocusTraversalKeysEnabled(false);
  101.  
  102. for(int y = 1; y <= 25; y++) {
  103. trainerLines.add(600-(34*y) - (bridge.getHeight()/2));
  104. validTrainerLines.add(true);
  105. }
  106. }
  107.  
  108. public void paintComponent(Graphics g) // draw graphics in the panel
  109. {
  110. if(y1 <= 200) {
  111. tD = 500;
  112. if(!shiftActivated) {
  113. for(int x = 0; x < trainerLines.size(); x++) {
  114. int oldLine = trainerLines.get(x);
  115. trainerLines.set(x, oldLine+tD);
  116. }
  117. }
  118. shiftActivated = true;
  119.  
  120. }
  121. if(y1 > 200) {
  122. if(shiftActivated) {
  123. tD = 0;
  124. for(int x = 0; x < trainerLines.size(); x++) {
  125. int oldLine = trainerLines.get(x);
  126. trainerLines.set(x, (oldLine-500));
  127. }
  128. }
  129. shiftActivated = false;
  130. }
  131.  
  132. super.paintComponent(g); // call superclass to make panel display correctly
  133. g.drawImage(water, 0, 0, this);
  134. g.drawImage(water, 0, 400, this);
  135. for(int y = 721; y < 1000; y+= grass.getHeight()) {
  136. for(int x = 15; x < bridge.getWidth(); x += grass.getWidth()) {
  137. g.drawImage(grass, x, y+tD, this);
  138. }
  139. }
  140. g.drawImage(verticalFence, 10, 721+tD, this);
  141. g.drawImage(verticalFence, 10, 750+tD, this);
  142. g.drawImage(verticalFence, bridge.getWidth(), 721+tD, this);
  143. g.drawImage(verticalFence, bridge.getWidth(), 750+tD, this);
  144. g.drawImage(horizontalFence, 10, 796+tD, this);
  145.  
  146.  
  147.  
  148. g.drawImage(opening, 7, 650+tD, this);
  149. g.drawImage(closing, 7, -318+tD, this);
  150. for(int y = 1; y <= 28; y++) {
  151. g.drawImage(bridge, 7, 708-(34*y) - bridge.getHeight() +tD, this);
  152. }
  153. boolean trainerIsRight = true;
  154. for(int y = 1; y <= 25; y++) {
  155. if(trainerIsRight) {
  156. g.drawImage(trainers.get(y-1).getPic(), bridge.getWidth() - 15 + trainers.get(y-1).getAddX(), 600-(34*y) - (bridge.getHeight()/2) +tD, this);
  157. trainers.get(y-1).setX(bridge.getWidth() - 15 + trainers.get(y-1).getAddX());
  158. trainerIsRight = false;
  159. }
  160. else {
  161. g.drawImage(trainers.get(y-1).getPic(), 15 + trainers.get(y-1).getAddX(), 600-(34*y) - (bridge.getHeight()/2) +tD, this);
  162. trainers.get(y-1).setX(15 + trainers.get(y-1).getAddX());
  163. trainerIsRight = true;
  164. }
  165. }
  166.  
  167. for(int x = 0; x < 5; x++) {
  168. g.drawImage(sidewaysBridge, 67+sidewaysBridge.getWidth()*x -8*x, 620 +tD, this);
  169. }
  170. for(int x = 0; x < 21; x++) {
  171. g.drawImage(smallHorizontalFence, 69+8*x, 650+tD, this);
  172. }
  173. for(int x = 0; x < 3; x++) {
  174. g.drawImage(smallVerticalFence, 73, 648 - 10*x + tD, this);
  175. }
  176. //g.drawImage()
  177. g.drawImage(pokeMart, 80, 598+tD, this);
  178. g.drawImage(pokeCenter, 150, 590+tD, this);
  179.  
  180. if(displayMain) {
  181. g.drawImage(main, x1, y1+tD, this);
  182. }
  183. }
  184.  
  185. public void readTrainerFile() throws FileNotFoundException, IOException {
  186. URL url = new URL("http://m.uploadedit.com/ba3s/1488652418722.txt");
  187. Scanner fr = new Scanner(url.openStream()).useDelimiter(",");
  188.  
  189. while (fr.hasNextLine()) {
  190. String vL = fr.nextLine();
  191. if(vL.equals("|||,")) {
  192. String picDirectory = fr.next();
  193. Trainer trainer = new Trainer(picDirectory);
  194. trainers.add(trainer);
  195. }
  196. }
  197. }
  198.  
  199. public void checkForBattle(int movement) throws InterruptedException, FileNotFoundException, IOException {
  200. z: for(int x = 0; x < trainerLines.size(); x++) {
  201.  
  202. if(y1+tD+movement == trainerLines.get(x) && validTrainerLines.get(x) == true) {
  203. int moveCounter = 0;
  204. if(x % 2 == 0) {
  205. while(trainers.get(x).getX()-10 > x1) {
  206. trainers.get(x).addX(-1);
  207. moveCounter++;
  208. repaint();
  209. }
  210. }
  211. if(x % 2 != 0) {
  212. while(trainers.get(x).getX()+10 < x1) {
  213. trainers.get(x).addX(1);
  214. moveCounter++;
  215. repaint();
  216. }
  217. }
  218. repaint();
  219. initiateBattle();
  220. validTrainerLines.set(x, false);
  221. break z;
  222. }
  223. }
  224. }
  225.  
  226. public void initiateBattle() throws FileNotFoundException, IOException, InterruptedException {
  227. if(!hasReadFile) {
  228. readInitFile();
  229. hasReadFile = true;
  230. }
  231. setFocusable(false);
  232. removeParty(oppParty);
  233. System.out.println("\nROUND " + round);
  234. stoppedLine = readFile(myParty, oppParty, stoppedLine);
  235. int didWin = battle(myParty, oppParty, trainerName, myBag, true);
  236.  
  237. resetParty(myParty);
  238. resetParty(oppParty);
  239. if(didWin == 1) {
  240. reward(myParty, oppParty, myBag);
  241. wins++;
  242. } else {
  243. losses++;
  244. }
  245. removeParty(oppParty);
  246. System.out.println("\nYour Party has been healed.\n");
  247. System.out.println("\nRecord: " + wins + " - " + losses);
  248. round++;
  249. calcEarnings(true, 0);
  250. setFocusable(true);
  251. System.out.println("\nMove using the arrow keys.");
  252. }
  253.  
  254. public void keyPressed(KeyEvent e) {
  255. if(e.getKeyCode() == KeyEvent.VK_LEFT) {
  256. if(walk) {
  257. main = mainLeftWalk1;
  258. walk = false;
  259. } else {
  260. main = mainLeftWalk2;
  261. walk = true;
  262. }
  263. repaint();
  264. if(x1 > 72 && x1 <235 && y1 > 650 && y1 < 683) {
  265. right = 235;
  266. down = 677;
  267. up = 650;
  268. } else {
  269. right = bridge.getWidth() - 15;
  270. down = 780;
  271. up = -318+tD;
  272. }
  273. if(x1-1 > left) {
  274. x1 = x1-1;
  275. repaint();
  276. try {
  277. checkForWild();
  278. } catch (FileNotFoundException ex) {} catch (IOException ex) {} catch (InterruptedException ex) {}
  279. }
  280. }
  281.  
  282.  
  283. if(e.getKeyCode() == KeyEvent.VK_RIGHT) {
  284. if(walk) {
  285. main = mainRightWalk1;
  286. walk = false;
  287. } else {
  288. main = mainRightWalk2;
  289. walk = true;
  290. }
  291. if(x1 > 50 && x1 <235 && y1 > 650 && y1 < 680) {
  292. right = 235;
  293. down = 677;
  294. up = 650;
  295. } else {
  296. right = bridge.getWidth() - 15;
  297. down = 780;
  298. up = -318+tD;
  299. }
  300. if(x1+1 < right) {
  301. x1 = x1+1;
  302. repaint();
  303. try {
  304. checkForWild();
  305. } catch (FileNotFoundException ex) {} catch (IOException ex) {} catch (InterruptedException ex) {}
  306. }
  307. }
  308.  
  309.  
  310. if(e.getKeyCode() == KeyEvent.VK_UP) {
  311. if(walk) {
  312. main = mainBackWalk1;
  313. walk = false;
  314. } else {
  315. main = mainBackWalk2;
  316. walk = true;
  317. }
  318. if(x1 > 63 && x1 <235 && y1 > 650 && y1 < 683) {
  319. right = 235;
  320. down = 677;
  321. up = 650;
  322. } else {
  323. right = bridge.getWidth() - 15;
  324. down = 780;
  325. up = -318+tD;
  326. }
  327. if(y1-1 > up) {
  328. y1 = y1-1;
  329. if(x1 >= 178 && x1 <= 186 && y1 <= 651) {
  330. setFocusable(false);
  331. displayMain = false;
  332. repaint();
  333. System.out.println("\nWelcome to the Poke Center!");
  334. displayPokeCenter();
  335. displayMain = true;
  336. setFocusable(true);
  337. System.out.println("\nMove using the arrow keys.");
  338. }
  339. if(x1 >= 108 && x1 <= 116 && y1 <= 651) {
  340. setFocusable(false);
  341. displayMain = false;
  342. repaint();
  343. System.out.println("\nWelcome to the Poke Mart!");
  344. displayPokeMart();
  345. displayMain = true;
  346. setFocusable(true);
  347. System.out.println("\nMove using the arrow keys.");
  348. }
  349. repaint();
  350. try {
  351. checkForWild();
  352. } catch (FileNotFoundException ex) {} catch (IOException ex) {} catch (InterruptedException ex) {}
  353. try {
  354. checkForBattle(1);
  355. } catch (InterruptedException ex) {} catch (FileNotFoundException ex) {} catch (IOException ex) {}
  356. }
  357. if(y1 -1 < -318 + tD) {
  358. System.out.println("Congratulations on winning the game! Your final record is " + wins + " - " + losses);
  359. System.exit(0);
  360. }
  361. }
  362.  
  363.  
  364. if(e.getKeyCode() == KeyEvent.VK_DOWN) {
  365. if(walk) {
  366. main = mainFrontWalk1;
  367. walk = false;
  368. } else {
  369. main = mainFrontWalk2;
  370. walk = true;
  371. }
  372. if(x1 > 63 && x1 <235 && y1 > 650 && y1 < 683) {
  373. right = 235;
  374. down = 677;
  375. up = 650;
  376. } else {
  377. right = bridge.getWidth() - 15;
  378. down = 780;
  379. up = -318+tD;
  380. }
  381. if(y1+1 < down) {
  382. y1 = y1+1;
  383. repaint();
  384. try {
  385. checkForWild();
  386. } catch (FileNotFoundException ex) {} catch (IOException ex) {} catch (InterruptedException ex) {}
  387. try {
  388. checkForBattle(1);
  389. } catch (InterruptedException ex) {} catch (FileNotFoundException ex) {} catch (IOException ex) {}
  390. }
  391. }
  392. }
  393.  
  394. @Override
  395. public void actionPerformed(ActionEvent e) {
  396. }
  397. @Override
  398. public void keyTyped(KeyEvent e) {
  399. }
  400. @Override
  401. public void keyReleased(KeyEvent e) {
  402. }
  403.  
  404. public void checkForWild() throws FileNotFoundException, IOException, InterruptedException {
  405. if(y1 >= 718 && y1 <= 1000 && x1 >= 15 && x1 <= 72) {
  406. int toHaveWild = (int)(100.0 * Math.random() + 1);
  407. if(toHaveWild == 1) {
  408. setUpWildPokemon();
  409. }
  410. }
  411. }
  412.  
  413. public void setUpWildPokemon() throws FileNotFoundException, IOException, InterruptedException {
  414. setFocusable(false);
  415. if(!hasReadFile) {
  416. readInitFile();
  417. hasReadFile = true;
  418. }
  419. int maxLevel = 0;
  420. for(int pSlot = 0; pSlot < 6; pSlot++) {
  421. if(myParty[pSlot] != null) {
  422. if(myParty[pSlot].getLevel() > maxLevel) {
  423. maxLevel = myParty[pSlot].getLevel();
  424. }
  425. }
  426. }
  427.  
  428. int level = 3 + (int)(Math.random() * ((maxLevel - 3) + 1));
  429. int adder = -1 + (int)(Math.random() * 3);
  430. level += adder;
  431. int HPMultiplier = 3 + (int)(Math.random() * ((5 - 3) + 1));
  432. int HPAdder = -5 + (int)(Math.random() * ((5 - -5) + 1));
  433. int HP = level * HPMultiplier + HPAdder;
  434.  
  435. determineWildPokemonTier(level, HP);
  436. setFocusable(true);
  437. System.out.println("\nMove using the arrow keys.");
  438.  
  439. }
  440.  
  441. public void determineWildPokemonTier(int level, int HP) throws FileNotFoundException, IOException, InterruptedException {
  442. int tier = 0;
  443. double randTierNumber = Math.random();
  444. randTierNumber = (int)randTierNumber * 100 +1;
  445.  
  446. int moves = 0;
  447. double randMovesNumber = Math.random();
  448. randMovesNumber = (int)randMovesNumber * 100 +1;
  449.  
  450. if(level <= 10) {
  451. tier = 1;
  452. randTierNumber = (int)randTierNumber * 100000 +1;
  453. if(randTierNumber == 50000) {
  454. tier = 4;
  455. }
  456. if(randMovesNumber <= 50) {
  457. moves = 1;
  458. }
  459. if(randMovesNumber > 50 && randMovesNumber <= 80) {
  460. moves = 2;
  461. }
  462. if(randMovesNumber > 80 && randMovesNumber <= 95) {
  463. moves = 3;
  464. }
  465. if(randMovesNumber > 95) {
  466. moves = 4;
  467. }
  468. }
  469. if(level >= 11 && level <= 20) {
  470. if(randTierNumber <= 45) {
  471. tier = 1;
  472. }
  473. if(randTierNumber > 45 && randTierNumber <= 90) {
  474. tier = 2;
  475. }
  476. if(randTierNumber > 90) {
  477. tier = 3;
  478. }
  479. randTierNumber = (int)randTierNumber * 10000 +1;
  480. if(randTierNumber == 5000) {
  481. tier = 4;
  482. }
  483. if(randMovesNumber <= 10) {
  484. moves = 1;
  485. }
  486. if(randMovesNumber > 10 && randMovesNumber <= 45) {
  487. moves = 2;
  488. }
  489. if(randMovesNumber > 45 && randMovesNumber <= 85) {
  490. moves = 3;
  491. }
  492. if(randMovesNumber > 85) {
  493. moves = 4;
  494. }
  495. }
  496. if(level >= 21 && level <= 30) {
  497. if(randTierNumber <= 25) {
  498. tier = 1;
  499. }
  500. if(randTierNumber > 25 && randTierNumber <= 70) {
  501. tier = 2;
  502. }
  503. if(randTierNumber > 70) {
  504. tier = 3;
  505. }
  506. randTierNumber = (int)randTierNumber * 5000 +1;
  507. if(randTierNumber == 2500) {
  508. tier = 4;
  509. }
  510. if(randMovesNumber <= 20) {
  511. moves = 2;
  512. }
  513. if(randMovesNumber > 20 && randMovesNumber <= 45) {
  514. moves = 3;
  515. }
  516. if(randMovesNumber > 45) {
  517. moves = 4;
  518. }
  519. }
  520. if(level >= 31) {
  521. if(randTierNumber <= 25) {
  522. tier = 2;
  523. }
  524. if(randTierNumber > 25) {
  525. tier = 3;
  526. }
  527. randTierNumber = (int)randTierNumber * 1000 +1;
  528. if(randTierNumber == 500) {
  529. tier = 4;
  530. }
  531. if(randMovesNumber <= 25) {
  532. moves = 3;
  533. }
  534. if(randMovesNumber > 25) {
  535. moves = 4;
  536. }
  537. }
  538. if(tier == 4) {
  539. level = 60;
  540. }
  541. determineWildMovesTier(tier, moves, level, HP);
  542. }
  543.  
  544. public void determineWildMovesTier(int tier, int moves, int level, int HP) throws FileNotFoundException, IOException, InterruptedException {
  545. ArrayList<Integer> wildMoves = new ArrayList<Integer>();
  546.  
  547. if(tier == 1) {
  548. for(int x = 0; x < moves; x++) {
  549. double randMovesNumber = Math.random();
  550. randMovesNumber = (int)(randMovesNumber * 100 +1);
  551.  
  552. if(randMovesNumber <= 70) {
  553. wildMoves.add(1);
  554. }
  555. if(randMovesNumber > 70) {
  556. wildMoves.add(2);
  557. }
  558. }
  559. }
  560. if(tier == 2) {
  561. for(int x = 0; x < moves; x++) {
  562. double randMovesNumber = Math.random();
  563. randMovesNumber = (int)(randMovesNumber * 100 +1);
  564.  
  565. if(randMovesNumber <= 30) {
  566. wildMoves.add(1);
  567. }
  568. if(randMovesNumber > 30 && randMovesNumber <= 70) {
  569. wildMoves.add(2);
  570. }
  571. if(randMovesNumber > 70) {
  572. wildMoves.add(3);
  573. }
  574. }
  575. }
  576. if(tier == 3) {
  577. for(int x = 0; x < moves; x++) {
  578. double randMovesNumber = Math.random();
  579. randMovesNumber = (int)(randMovesNumber * 100 +1);
  580.  
  581. if(randMovesNumber <= 20) {
  582. wildMoves.add(1);
  583. }
  584. if(randMovesNumber > 20 && randMovesNumber <= 50) {
  585. wildMoves.add(2);
  586. }
  587. if(randMovesNumber > 50) {
  588. wildMoves.add(3);
  589. }
  590. }
  591. }
  592. if(tier == 4) {
  593. for(int x = 0; x < moves; x++) {
  594. wildMoves.add(3);
  595. }
  596. }
  597. createWildPokemon(tier, wildMoves, level, HP);
  598. }
  599.  
  600. public void createWildPokemon(int tier, ArrayList<Integer> wildMoves, int level, int HP) throws FileNotFoundException, IOException, InterruptedException {
  601. boolean foundPokemon = false;
  602. String line = "";
  603. String name = "";
  604. ArrayList<String> types = new ArrayList<String>();
  605. Pokemon wildPokemon = null;
  606. while(!foundPokemon) {
  607. URL url = new URL("http://m.uploadedit.com/ba3s/1488652544248.txt");
  608. Scanner sc = new Scanner(url.openStream()).useDelimiter(",");
  609.  
  610. int lineNumber = (int)(273 * Math.random() +1);
  611. if(lineNumber % 2 == 0) {
  612. lineNumber++;
  613. }
  614. for(int i = 0; i < lineNumber; i++) {
  615. sc.nextLine();
  616. }
  617. line = sc.nextLine();
  618. line = ",".concat(line);
  619. Scanner sc2 = new Scanner(line).useDelimiter(",");
  620. if(Integer.parseInt(sc2.next()) == tier) {
  621. name = sc2.next();
  622. while(sc2.hasNext()) {
  623. String type = sc2.next();
  624. if(type != "/" || type != "," || type != "/,") {
  625. types.add(type);
  626. } else {
  627. wildPokemon = new Pokemon(name, HP, level, types.get(0));
  628. foundPokemon = true;
  629. }
  630. }
  631. wildPokemon = new Pokemon(name, HP, level, types.get(0));
  632. foundPokemon = true;
  633. }
  634. }
  635.  
  636. if(foundPokemon) {
  637. createWildMoves(tier, types, wildMoves, wildPokemon);
  638. }
  639. }
  640.  
  641. public void createWildMoves(int tier, ArrayList<String> types, ArrayList<Integer> wildMoves, Pokemon wildPokemon) throws FileNotFoundException, IOException, InterruptedException {
  642. for(int x = 0; x < wildMoves.size(); x++) {
  643. String moveType = determineWildMoveType(types);
  644. ArrayList< String> lines = new ArrayList<String>() ;
  645. boolean foundMove = false;
  646. String line = "";
  647. int tryCount = 0;
  648. URL url = new URL("http://m.uploadedit.com/ba3s/1488652222901.txt");
  649. Scanner sc = new Scanner(url.openStream()).useDelimiter(",");
  650. for(int y = 0; y <= 329; y= y+2) {
  651. sc.nextLine();
  652. String s = sc.nextLine();
  653. lines.add(s);
  654. }
  655. while(!foundMove) {
  656.  
  657. int lineNumber = (int)(lines.size() * Math.random());
  658.  
  659. line = lines.get(lineNumber);
  660. line = ",".concat(line);
  661. Scanner sc2 = new Scanner(line).useDelimiter(",");
  662.  
  663.  
  664. String posMoveType = sc2.next();
  665. if(posMoveType.equals(moveType)) {
  666. int posTier = sc2.nextInt();
  667. if(tryCount == 2000) {
  668. System.out.println("Recalculating...");
  669. posTier -= 1;
  670. wildMoves.set(x, wildMoves.get(x)-1);
  671. }
  672. if(tryCount == 4000) {
  673. posTier += 2;
  674. wildMoves.set(x, wildMoves.get(x)+2);
  675. }
  676. if(tryCount == 6000) {
  677. moveType = determineWildMoveType(types);
  678. posTier -= 1;
  679. wildMoves.set(x, wildMoves.get(x)-1);
  680. tryCount = 0;
  681. }
  682. if(posTier == wildMoves.get(x)) {
  683. String name = sc2.next();
  684. int PP = sc2.nextInt();
  685. double damageMultiplier = sc2.nextDouble();
  686. int damage = (int)Math.round(damageMultiplier * wildPokemon.getLevel());
  687. int accuracy = sc2.nextInt();
  688. int speed = sc2.nextInt();
  689. Move newMove = new Move(name, PP, damage, accuracy, speed, moveType);
  690. wildPokemon.addMove(newMove, x);
  691. foundMove = true;
  692. }
  693. tryCount++;
  694. }
  695.  
  696. }
  697. }
  698. initiateWildBattle(wildPokemon);
  699. }
  700.  
  701. public void initiateWildBattle(Pokemon wildPokemon) throws IOException, FileNotFoundException, InterruptedException {
  702. if(!hasReadFile) {
  703. readInitFile();
  704. }
  705.  
  706. resetParty(oppParty);
  707. oppParty[0] = wildPokemon;
  708.  
  709. int result = battle(myParty, oppParty, trainerName, myBag, false);
  710. if(result == 1) {
  711. calcEarnings(false, wildPokemon.getLevel());
  712. }
  713. resetParty(oppParty);
  714. }
  715.  
  716. public static String determineWildMoveType(ArrayList<String> types) {
  717. int n = types.size();
  718. double total = 0;
  719.  
  720. for(int i = 0; i < n; i++) {
  721. total += Math.pow(2,i);
  722. }
  723. double magicNum = 100/total;
  724. double ogMN = magicNum;
  725.  
  726. int randNum = (int)(100.0 * Math.random() + 1);
  727. double sum = 0;
  728.  
  729. for(int i = 0; i < n; i++) {
  730. if(randNum <= magicNum) {
  731. System.out.println("\n"+types.get(n - i -1)+"\n");
  732. return types.get(n - i -1);
  733.  
  734. } else {
  735. magicNum += Math.pow(2,i+1)*ogMN;
  736. }
  737. }
  738. return types.get(0);
  739. }
  740.  
  741. public static void main(String[] args) throws FileNotFoundException, IOException {
  742. // TODO code application logic here
  743.  
  744.  
  745. PokemonBattle panel = new PokemonBattle(); // window for drawing
  746. JFrame application = new JFrame(); // the program itself
  747.  
  748. application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // set frame to exit
  749. // when it is closed
  750. application.add(panel);
  751.  
  752.  
  753. application.setSize(260, 1000); // window is 500 pixels wide, 400 high
  754. application.setVisible(true);
  755. application.setResizable(false);
  756.  
  757. System.out.println("Welcome to Pokemon Simulator. Please enter your name.");
  758. Scanner sc = new Scanner(System.in);
  759. trainerName = "Trainer ".concat(sc.nextLine());
  760. System.out.println("Welcome " + trainerName + "!");
  761. System.out.println();
  762. System.out.println("There are 25 opponents in the game. ");
  763. System.out.println("As you progress, the opponents increase in difficulty and your Pokemon gain exp and level up as you defeat enemies. ");
  764. System.out.println("After each opponent you defeat you get the option of either taking one of their Pokemon to add to your party");
  765. System.out.println("or receiving a random item. After each battle your Pokemon's moves and HP get restored. ");
  766. System.out.println("The goal is to win as many games as possible.");
  767. System.out.println("\nMove using the arrow keys.");
  768.  
  769.  
  770.  
  771. }
  772.  
  773. public void readInitFile() throws FileNotFoundException, MalformedURLException, IOException {
  774. for(int x = 0; x < 100; x++) {
  775. Item masterBall = new Ball("Master Ball", 100000, 0);
  776. Item ultraBall = new Ball("Ultra Ball", 50, 0);
  777. Item greatBall = new Ball("Great Ball", 40, 0);
  778. Item pokeBall = new Ball("Poke Ball", 30, 0);
  779. myBag.add(masterBall); myBag.add(ultraBall); myBag.add(greatBall); myBag.add(pokeBall);
  780. }
  781. File f = new File("/Users/bensauberman/Desktop/PokemonSprites/MyPokeMonFile.txt");
  782. Scanner fr = new Scanner(f).useDelimiter(",");
  783. //URL url = new URL("http://m.uploadedit.com/ba3s/1488652275683.txt");
  784. //Scanner fr = new Scanner(url.openStream()).useDelimiter(",");
  785.  
  786. while (fr.hasNextLine()) {
  787. String vL = fr.next();
  788. if(vL.equals("||")) {
  789. fr.nextLine();
  790. String info = fr.nextLine();
  791. addPokemon(info, myParty);
  792. }
  793. if(vL.equals("|")) {
  794. fr.nextLine();
  795. String info = fr.nextLine();
  796. addMove(info, myParty);
  797. }
  798. if(vL.charAt(0) == ('/')) {
  799. fr.nextLine();
  800. }
  801. }
  802. }
  803.  
  804. public int readFile(Pokemon myParty[], Pokemon oppParty[], int line) throws FileNotFoundException, MalformedURLException, IOException {
  805.  
  806. URL url = new URL("http://m.uploadedit.com/ba3s/1488652045394.txt");
  807. Scanner fr = new Scanner(url.openStream()).useDelimiter(",");
  808. int lineCounter = line;
  809.  
  810. for(int i = 0; i < line; i++) {
  811. fr.nextLine();
  812. }
  813. while (fr.hasNextLine()) {
  814. String vL = fr.next();
  815. if(vL.equals("||||")) {
  816. fr.nextLine();
  817. lineCounter+=2;
  818. String info = fr.nextLine();
  819. addPokemon(info, oppParty);
  820. }
  821. if(vL.equals("|||")) {
  822. fr.nextLine();
  823. lineCounter+=2;
  824. String info = fr.nextLine();
  825. addMove(info, oppParty);
  826. }
  827. if(vL.equals("|||||")) {
  828. lineCounter++;
  829. stoppedLine = lineCounter;
  830. return lineCounter;
  831. }
  832. if(vL.charAt(0) != ('|') ) {
  833. fr.nextLine();
  834. lineCounter++;
  835. }
  836. }
  837. return lineCounter;
  838. }
  839.  
  840. public static void printParty(Pokemon party[], boolean showNumbers) {
  841. if(showNumbers) {
  842. System.out.println("Pokemon HP Level Type");
  843. } else {
  844. System.out.println("Pokemon HP Level Type");
  845. }
  846. for(int x = 0; x < 6; x++) {
  847. if(party[x] != null) {
  848. int spaceCount = 0;
  849. if(showNumbers) {
  850. spaceCount = (16 - party[x].getName().length());
  851. } else {
  852. spaceCount = (14 - party[x].getName().length());
  853. }
  854. StringBuilder spaces = new StringBuilder();
  855. for(int y = 0; y < spaceCount; y++) {
  856. spaces.append(" ");
  857. }
  858. if(showNumbers) {
  859. System.out.print(x+1 + ": " + party[x].getName() + spaces + party[x].getnHP());
  860. } else {
  861. System.out.print(party[x].getName() + spaces + party[x].getnHP());
  862. }
  863. if(party[x].getnHP() >= 100) {
  864. System.out.print(" " + party[x].getLevel());
  865. } else if(party[x].getnHP() >= 10 && party[x].getnHP() <= 99) {
  866. System.out.print(" " + party[x].getLevel());
  867. } else {
  868. System.out.print(" " + party[x].getLevel());
  869. }
  870. if(party[x].getLevel() >= 10) {
  871. System.out.print(" " + party[x].getType());
  872. } else {
  873. System.out.print(" " + party[x].getType());
  874. }
  875. System.out.println();
  876. }
  877. }
  878. }
  879.  
  880. public void addPokemon(String info, Pokemon party[]) {
  881. Scanner fr = new Scanner(info).useDelimiter(",");
  882. String pName = fr.next();
  883. int pHP = fr.nextInt();
  884. int pLevel = fr.nextInt();
  885. String pType = fr.next();
  886. Pokemon newPokemon = new Pokemon(pName, pHP, pLevel, pType);
  887.  
  888. for(int pSlot = 0; pSlot < 6; pSlot++) {
  889. if(party[pSlot] == null || party[pSlot].getName().toUpperCase().equals(pName.toUpperCase())){
  890. party[pSlot] = newPokemon;
  891. break;
  892. }
  893.  
  894. }
  895. }
  896.  
  897. public void addMove(String info, Pokemon party[]) {
  898. Scanner fr = new Scanner(info).useDelimiter(",");
  899. String pName = fr.next();
  900. String mName = fr.next();
  901. int mPP = fr.nextInt();
  902. int mDamage = fr.nextInt();
  903. int mAccuracy = fr.nextInt();
  904. int mSpeed = fr.nextInt();
  905. String mType = fr.next();
  906.  
  907. Move newMove = new Move(mName, mPP, mDamage, mAccuracy, mSpeed, mType);
  908. int pSlot = 10;
  909. y: for(int x = 0; x < 6; x++) {
  910. if(party[x]!= null) {
  911. if(party[x].getName().toUpperCase().equals(pName.toUpperCase())) {
  912. pSlot = x;
  913. break y;
  914. }
  915. }
  916.  
  917. }
  918. if(pSlot == 10) {
  919. throw new IllegalArgumentException("The move " + mName + " cannot be added because the "
  920. + "Pokemon it belongs to is not currently in the party.");
  921. }
  922.  
  923. boolean freeSpot = false;
  924.  
  925. y: for(int mSlot = 0; mSlot < 4; mSlot++) {
  926. if(party[pSlot].getMoves()[mSlot] == null) {
  927. party[pSlot].getMoves()[mSlot] = newMove;
  928. freeSpot = true;
  929. break y;
  930. }
  931. }
  932.  
  933.  
  934. //REPLACES MOVE IF ALL 4 SLOTS ARE FILLED
  935. if(!freeSpot) {
  936. System.out.println("Which move would you like to replace for " + mName);
  937. party[pSlot].printMoves();
  938. System.out.println("4: Do not add.");
  939. Scanner sc = new Scanner(System.in);
  940. int mSlot = sc.nextInt();
  941.  
  942. if(mSlot >= 0 && mSlot <= 3) {
  943. party[pSlot].addMove(newMove, mSlot);
  944. System.out.println(mName + " added to " + pName);
  945. }
  946. else {
  947. System.out.println(mName + " not added.");
  948. }
  949. }
  950. }
  951.  
  952. public int battle(Pokemon myParty[], Pokemon oppParty[], String trainerName, ArrayList<Item> myBag, boolean isTrainer) throws FileNotFoundException, IOException, InterruptedException {
  953. if(isTrainer) {
  954.  
  955. System.out.println("\n\nWelcome to the battle!");
  956.  
  957. int oppPokemonCounter = 0;
  958. for(int x = 0; x < 6; x++) {
  959. if(oppParty[x] != null) {
  960. oppPokemonCounter++;
  961. }
  962. }
  963. System.out.println("Your opponent has " + oppPokemonCounter + " pokemon.");
  964. }
  965.  
  966.  
  967.  
  968. if(!isTrainer) {
  969. System.out.println("A wild pokemon appeared.");
  970. System.out.println("The pokemon is a level " + oppParty[0].getLevel() + " " + oppParty[0].getName());
  971. }
  972.  
  973. Pokemon myPokemon = pickMyPokemon(myParty, null);
  974. Pokemon oppPokemon = pickOppPokemon(oppParty);
  975. System.out.println();
  976.  
  977. while(checkForValidPokemon(myParty) && checkForValidPokemon(oppParty)) {
  978. System.out.println("\n" + trainerName + "'s Party: ");
  979. printParty(myParty, false);
  980. System.out.println("\nOpponent's Party: ");
  981. printParty(oppParty, false);
  982. System.out.println();
  983.  
  984. Move myMove = null;
  985. Move oppMove = null;
  986.  
  987. //MY OPTIONS
  988. boolean validMove = false;
  989. while(!validMove) {
  990. System.out.println("\nWhat would you like to do?");
  991. int userChoice = chooseOption();
  992. if(userChoice == 1) {
  993. int mSlot = pickMyMove(myPokemon, myParty);
  994. if(mSlot == -2) {
  995. userChoice = 2;
  996. validMove = true;
  997. }
  998. if(mSlot == -1) {
  999. validMove = false;
  1000. } else {
  1001. myMove = myPokemon.getMoves()[mSlot];
  1002. validMove = true;
  1003. }
  1004. }
  1005. if(userChoice == 2) {
  1006. Pokemon oldPokemon = myPokemon;
  1007. myPokemon = pickMyPokemon(myParty, myPokemon);
  1008. if(oldPokemon.getName() != (myPokemon.getName())) {
  1009. validMove = true;
  1010. }
  1011. System.out.println("That Pokemon is already in battle.");
  1012.  
  1013. }
  1014. if(userChoice == 3) {
  1015. if(myBag.size() > 0) {
  1016. boolean hasBeenUsed = chooseItem(myBag, myParty, oppParty, isTrainer);
  1017. if(hasBeenUsed) {
  1018. validMove = true;
  1019. }
  1020. } else {
  1021. System.out.println("Bag is empty. Pick another option.\n");
  1022. }
  1023. }
  1024. if(userChoice == 4) {
  1025. boolean didRun = run(isTrainer);
  1026. if(didRun) {
  1027. validMove = true;
  1028. return 2;
  1029. }
  1030. }
  1031. }
  1032.  
  1033. //OPPONENTS OPTIONS
  1034. if(!checkForValidPokemon(oppParty)) {
  1035. System.out.println();
  1036. printResult(true);
  1037. return 1; //WIN
  1038. }
  1039.  
  1040. boolean hasMadeTurn = false;
  1041. while(!hasMadeTurn) {
  1042.  
  1043. if(checkForValidMove(oppPokemon) == false) {
  1044. oppPokemon = pickOppPokemon(oppParty);
  1045. System.out.println("\n---------------------------");
  1046. System.out.println("The opponent sends out " + oppPokemon);
  1047. System.out.println("---------------------------");
  1048. hasMadeTurn = true;
  1049. }
  1050.  
  1051. boolean hasPickedValidMove = false;
  1052. int randomMoveCounter = 0;
  1053. while(!hasPickedValidMove) {
  1054. int randomMove = (int)(4.0 * Math.random());
  1055. randomMoveCounter++;
  1056. if(oppPokemon.getMoves()[randomMove] != null) {
  1057. if(oppPokemon.getMoves()[randomMove].getnPP() > 0) {
  1058. oppMove = oppPokemon.getMoves()[randomMove];
  1059. hasPickedValidMove = true;
  1060. hasMadeTurn = true;
  1061. }
  1062. }
  1063.  
  1064. if(randomMoveCounter >= 200) {
  1065. oppPokemon = pickOppPokemon(oppParty);
  1066. System.out.println("\nThe opponent sends out " + oppPokemon);
  1067. hasMadeTurn = true;
  1068. hasPickedValidMove = true;
  1069. }
  1070. }
  1071. }
  1072.  
  1073. int checkFaint = useMoves(myMove, oppMove, myPokemon, oppPokemon, isTrainer);
  1074. if(checkFaint == 1) {
  1075. oppPokemon = pickOppPokemon(oppParty);
  1076. }
  1077. if(checkFaint == 2) {
  1078. myPokemon = pickMyPokemon(myParty, null);
  1079. }
  1080. }
  1081.  
  1082. if(!checkForValidPokemon(myParty)) {
  1083. System.out.println();
  1084. printResult(false);
  1085. return 0; //LOSE
  1086. }
  1087. return 1;
  1088.  
  1089.  
  1090. }
  1091.  
  1092. public static int useMoves(Move myMove, Move oppMove, Pokemon myPokemon, Pokemon oppPokemon, boolean isTrainer) throws FileNotFoundException, IOException, InterruptedException {
  1093. int myMoveSlot = -1;
  1094. int oppMoveSlot = -1;
  1095. boolean checkFaint = false;
  1096. for(int x = 0; x < 4; x++) {
  1097. if(myMove != null) {
  1098. if(myPokemon.getMoves()[x] != null) {
  1099. if(myMove.getName().toUpperCase().equals(myPokemon.getMoves()[x].getName().toUpperCase())) {
  1100. myMoveSlot = x;
  1101. }
  1102. }
  1103. }
  1104. if(oppMove != null) {
  1105. if(oppPokemon.getMoves()[x] != null) {
  1106. if(oppMove.getName().toUpperCase().equals(oppPokemon.getMoves()[x].getName().toUpperCase())) {
  1107. oppMoveSlot = x;
  1108. }
  1109. }
  1110. }
  1111. }
  1112. if(myMove == null && oppMove == null) {
  1113. return 0;
  1114. }
  1115. if(myMove != null && oppMove == null) {
  1116. checkFaint = useMove(myMove, myPokemon, oppPokemon, isTrainer);
  1117. if(checkFaint) {
  1118. return 0;
  1119. } else {
  1120. return 1;
  1121. }
  1122. }
  1123. if(myMove == null && oppMove != null) {
  1124. checkFaint = useMove(oppMove, oppPokemon, myPokemon, isTrainer);
  1125. if(checkFaint) {
  1126. return 0;
  1127. } else {
  1128. return 2;
  1129. }
  1130. }
  1131.  
  1132. if(myMove != null && oppMove != null) {
  1133. if((myMove.getSpeed() * myPokemon.getLevel()) >= (oppMove.getSpeed() * oppPokemon.getLevel())) {
  1134. checkFaint = useMove(myMove, myPokemon, oppPokemon, isTrainer);
  1135. if(checkFaint) {
  1136. checkFaint = useMove(oppMove, oppPokemon, myPokemon, isTrainer);
  1137. if(checkFaint) {
  1138. return 0;
  1139. } else {
  1140. return 2;
  1141. }
  1142. }
  1143. else {
  1144. return 1;
  1145. }
  1146. }
  1147.  
  1148. if(((oppMove.getSpeed() * oppPokemon.getLevel())) > ((myMove.getSpeed()) * myPokemon.getLevel())|| oppMoveSlot == -1) {
  1149. checkFaint = useMove(oppMove, oppPokemon, myPokemon, isTrainer);
  1150. if(checkFaint) {
  1151. checkFaint = useMove(myMove, myPokemon, oppPokemon, isTrainer);
  1152. if(checkFaint) {
  1153. return 0;
  1154. } else {
  1155. return 1;
  1156. }
  1157. }
  1158. else {
  1159. return 2;
  1160. }
  1161. }
  1162. }
  1163.  
  1164. return 0;
  1165. }
  1166.  
  1167. public static boolean useMove(Move attMove, Pokemon attPokemon, Pokemon defPokemon, boolean isTrainer) throws FileNotFoundException, IOException, InterruptedException {
  1168. int accuracyGen = (int)(100.0 * Math.random() +1);
  1169. System.out.println();
  1170. if(attMove.getAccuracy() > accuracyGen) {
  1171. int criticalGen = (int)(100.0 * Math.random() +1);
  1172. boolean isCritical = false;
  1173. int criticalMultiplier = 1;
  1174. if(criticalGen <= 5) {
  1175. isCritical = true;
  1176. criticalMultiplier = 2;
  1177. }
  1178. int HPBeforeAttack = defPokemon.getnHP();
  1179. attMove.decnPP();
  1180. double effectiveMultiplier = decideEffectiveness(attMove.getType(), defPokemon.getType());
  1181.  
  1182. System.out.println("---------------------------");
  1183. defPokemon.setnHP((int)(attMove.getDamage() * (-effectiveMultiplier) * (criticalMultiplier)));
  1184. if(defPokemon.getnHP() <= 0) {
  1185. System.out.println(attPokemon.getName() + " used " + attMove.getName() + " and " + defPokemon.getName() + " fainted.");
  1186. if(effectiveMultiplier == 0.5) {
  1187. System.out.println(attMove.getName() + " was not very effective.");
  1188. }
  1189. if(effectiveMultiplier == 2.0) {
  1190. System.out.println(attMove.getName() + " was super effective!");
  1191. }
  1192. if(criticalMultiplier == 2){
  1193. System.out.println(attMove.getName() + " was a critical hit!");
  1194. }
  1195. calcEXP(attPokemon, defPokemon, isTrainer);
  1196. Thread.sleep(750);
  1197. return false;
  1198. } else if (effectiveMultiplier == 0) {
  1199. System.out.println(attMove.getName() + " does not affect " + defPokemon.getName());
  1200. }
  1201. else {
  1202. System.out.println(attPokemon.getName() + " used " + attMove.getName() + " decreasing " + defPokemon.getName() + "'s HP from "
  1203. + HPBeforeAttack + " to " + defPokemon.getnHP());
  1204. if(effectiveMultiplier == 0.5) {
  1205. System.out.println(attMove.getName() + " was not very effective.");
  1206. }
  1207. if(effectiveMultiplier == 2.0) {
  1208. System.out.println(attMove.getName() + " was super effective!");
  1209. }
  1210. if(criticalMultiplier == 2){
  1211. System.out.println(attMove.getName() + " was a critical hit!");
  1212. }
  1213. System.out.println("---------------------------");
  1214. Thread.sleep(750);
  1215. return true;
  1216. }
  1217. } else {
  1218. System.out.println("---------------------------");
  1219. System.out.println(attPokemon.getName() + " tried to use " + attMove.getName() +
  1220. " but the attack missed!");
  1221. System.out.println("---------------------------");
  1222. Thread.sleep(750);
  1223. return true;
  1224. }
  1225. System.out.println("---------------------------");
  1226. Thread.sleep(750);
  1227. return true;
  1228. }
  1229.  
  1230. public static Pokemon pickMyPokemon(Pokemon myParty[], Pokemon myPokemon) {
  1231. System.out.println();
  1232. System.out.println();
  1233. if(checkForValidPokemon(myParty) == false) {
  1234. System.out.println("No more available Pokemon.");
  1235. return null;
  1236. }
  1237. printParty(myParty, true);
  1238. boolean isValid = false;
  1239. while(!isValid) {
  1240. System.out.println("\nWhich Pokemon would you like to send out to battle?");
  1241. Scanner s = new Scanner(System.in);
  1242. System.out.println();
  1243. printParty(myParty, true);
  1244. String requested = s.next();
  1245. boolean validName = false;
  1246. for(int x = 0; x < 6; x++) {
  1247. if(myParty[x] != null) {
  1248. if(myParty[x].getName().toUpperCase().equals(requested.toUpperCase()) || Integer.parseInt(requested)-1 == x) {
  1249. validName = true;
  1250. if(myParty[x].getnHP() <= 0) {
  1251. System.out.println(myParty[x].getName() + " has an HP of 0 and can therefore not battle. "
  1252. + " Choose another Pokemon.");
  1253. }
  1254. else if (myPokemon != null){
  1255. if(myPokemon.getName().toUpperCase().equals(requested.toUpperCase()) && myPokemon.getnHP() > 0) {
  1256. return myParty[x];
  1257. }
  1258. }
  1259. if(myPokemon != null || myPokemon == null) {
  1260. if(myParty[x].getnHP() > 0) {
  1261. isValid = true;
  1262. return myParty[x];
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. if(!validName) {
  1269. System.out.println("The Pokemon entered is not in the party and therefore cannot be sent out."
  1270. + " Choose another Pokemon.");
  1271. }
  1272. }
  1273. return null;
  1274. }
  1275.  
  1276. public static Pokemon pickOppPokemon(Pokemon oppParty[]) {
  1277.  
  1278. for(int x = 0; x < 6; x++) {
  1279. if(oppParty[x] != null) {
  1280. if(oppParty[x].getnHP() > 0) {
  1281. if(checkForValidMove(oppParty[x])) {
  1282. System.out.println("\nThe opponent sends out " + oppParty[x].getName());
  1283. return oppParty[x];
  1284. }
  1285. }
  1286. }
  1287. }
  1288. return null;
  1289.  
  1290. }
  1291.  
  1292. public static Boolean checkForValidPokemon(Pokemon party[]) {
  1293. for(int x = 0; x < 6; x++) {
  1294. if(party[x] != null && party[x].getnHP() > 0) {
  1295. return true;
  1296. }
  1297. }
  1298. return false;
  1299. }
  1300.  
  1301. public static Boolean checkForValidMove(Pokemon pokemon) {
  1302. for(int x = 0; x < 4; x++) {
  1303. if(pokemon.getMoves()[x] != null) {
  1304. if(pokemon.getMoves()[x].getnPP() > 0) {
  1305. return true;
  1306. }
  1307. }
  1308. }
  1309. return false;
  1310. }
  1311.  
  1312. public static int pickMyMove(Pokemon myPokemon, Pokemon myParty[]) {
  1313.  
  1314. if(!checkForValidMove(myPokemon)) {
  1315. System.out.println("This Pokemon has no PP left in any of his moves. Please change Pokemon.");
  1316. return -2;
  1317. }
  1318.  
  1319. System.out.println("\nPick a move. Press '0' to Exit.");
  1320. myPokemon.printMoves();
  1321.  
  1322. boolean isValid = false;
  1323. int requestedMove = -1;
  1324.  
  1325. while(!isValid) {
  1326. Scanner s = new Scanner(System.in);
  1327. String requestedMoveWord = s.nextLine();
  1328. if(requestedMoveWord.equals("0")) {
  1329. return -1;
  1330. }
  1331. if(((myPokemon.getMoves()[0] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[0].getName().toUpperCase()))) || (requestedMoveWord.equals("1"))) {
  1332. requestedMove = 1;
  1333. }
  1334. if(((myPokemon.getMoves()[1] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[1].getName().toUpperCase()))) || (requestedMoveWord.equals("2"))) {
  1335. requestedMove = 2;
  1336. }
  1337. if(((myPokemon.getMoves()[2] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[2].getName().toUpperCase()))) || (requestedMoveWord.equals("3"))) {
  1338. requestedMove = 3;
  1339. }
  1340. if(((myPokemon.getMoves()[3] != null) && (requestedMoveWord.toUpperCase().equals(myPokemon.getMoves()[3].getName().toUpperCase()))) || (requestedMoveWord.equals("4"))) {
  1341. requestedMove = 4;
  1342. }
  1343.  
  1344. if(requestedMove >= 1 && requestedMove <= 4) {
  1345. if(myPokemon.getMoves()[requestedMove-1] != null) {
  1346. if(myPokemon.getMoves()[requestedMove-1].getnPP() > 0) {
  1347. return requestedMove-1;
  1348. } else {
  1349. System.out.println("That move has no PP left. Please pick another move.");
  1350. }
  1351. } else {
  1352. System.out.println("There is no move in that slot. Please pick a valid move.");
  1353. }
  1354. } else {
  1355. System.out.println("The entered number must be a valid number between 1 and 4.");
  1356. }
  1357. }
  1358. return -1;
  1359. }
  1360.  
  1361. public void printResult(boolean result) {
  1362. if(result) {
  1363. System.out.println("You win the battle!");
  1364. }
  1365. if(!result) {
  1366. System.out.println("You lose the battle.");
  1367. int ogEarnings = earnings;
  1368. earnings = earnings/2;
  1369. System.out.println("You have been sent to the Poke Center to reheal.\n Your Earnings have"
  1370. + " been cut from " + ogEarnings + " to " + earnings);
  1371. x1 = 182; y1 = 651;
  1372. main = mainFrontWalk1;
  1373. }
  1374. }
  1375.  
  1376. public static int chooseOption() {
  1377. System.out.println("1: Pick a move.");
  1378. System.out.println("2: Change Pokemon.");
  1379. System.out.println("3: Use item.");
  1380. System.out.println("4: Run Away.");
  1381.  
  1382. int userChoice = 0;
  1383. boolean isValid = false;
  1384. while (isValid == false) {
  1385. Scanner s = new Scanner(System.in);
  1386. try {
  1387. userChoice = s.nextInt();
  1388. } catch(InputMismatchException e) {
  1389. System.out.println("Please enter a valid option.");
  1390. break;
  1391. }
  1392. if(userChoice < 1 || userChoice > 4) {
  1393. System.out.println("Please enter a valid option.");
  1394. } else {
  1395. isValid = true;
  1396. }
  1397. }
  1398. return userChoice;
  1399.  
  1400. }
  1401.  
  1402. public static int effectivenessNumber(String type) {
  1403. switch(type) {
  1404. case "Normal":
  1405. return 0;
  1406. case "Fire":
  1407. return 1;
  1408. case "Water":
  1409. return 2;
  1410. case "Electric":
  1411. return 3;
  1412. case "Grass":
  1413. return 4;
  1414. case "Ice":
  1415. return 5;
  1416. case "Fighting":
  1417. return 6;
  1418. case "Poison":
  1419. return 7;
  1420. case "Ground":
  1421. return 8;
  1422. case "Flying":
  1423. return 9;
  1424. case "Psychic":
  1425. return 10;
  1426. case "Bug":
  1427. return 11;
  1428. case "Rock":
  1429. return 12;
  1430. case "Ghost":
  1431. return 13;
  1432. case "Dragon":
  1433. return 14;
  1434. case "Dark":
  1435. return 15;
  1436. case "Steel":
  1437. return 16;
  1438. }
  1439. return -1;
  1440. }
  1441.  
  1442. public static double decideEffectiveness(String moveTypeWord, String defPokemonTypeWord) throws FileNotFoundException, MalformedURLException, IOException {
  1443. int moveType = effectivenessNumber(moveTypeWord);
  1444. int defPokemonType = effectivenessNumber(defPokemonTypeWord);
  1445.  
  1446. double[][] effectivenessChart = new double[17][17];
  1447. URL url = new URL("http://m.uploadedit.com/ba3s/1488232904670.txt");
  1448. Scanner fr2 = new Scanner(url.openStream()).useDelimiter(",");
  1449. for(int x = 0; x < 17; x++) {
  1450. for(int y = 0; y < 17; y++) {
  1451. effectivenessChart[x][y] = fr2.nextDouble();
  1452. }
  1453. fr2.nextLine();
  1454. }
  1455. fr2.close();
  1456.  
  1457. return effectivenessChart[moveType][defPokemonType];
  1458. }
  1459.  
  1460. public static void calcEXP(Pokemon attPokemon, Pokemon defPokemon, boolean isTrainer) throws InterruptedException {
  1461. int previousEXP = attPokemon.getEXP();
  1462. int previousMaxEXP = attPokemon.getEXP();
  1463.  
  1464. int divider = 1;
  1465. if(!isTrainer) {
  1466. divider = 2;
  1467. }
  1468. attPokemon.addEXP(((defPokemon.getLevel() * 10)+5) / divider);
  1469.  
  1470. while(attPokemon.getEXP() >= attPokemon.getMaxEXP()) {
  1471. attPokemon.incLevel();
  1472. attPokemon.setMaxEXP();
  1473. attPokemon.setEXP(attPokemon.getEXP() - previousMaxEXP);
  1474. Thread.sleep(1300);
  1475. System.out.println("---------------------------");
  1476. System.out.println(attPokemon.getName() + " has grown from Level " + (attPokemon.getLevel()-1) + " to Level " + attPokemon.getLevel());
  1477.  
  1478. attPokemon.setrHP((int)(attPokemon.getrHP() * .05));
  1479. Thread.sleep(1300);
  1480. System.out.println(attPokemon.getName() + "'s Max HP has now increased to " + attPokemon.getrHP() + "\n");
  1481. for(int x = 0; x < 4; x++) {
  1482. if(attPokemon.getMoves()[x] != null) {
  1483. attPokemon.getMoves()[x].setDamage();
  1484. System.out.println(attPokemon.getName() + "'s " + attPokemon.getMoves()[x].getName() + " has increased its damage to " + attPokemon.getMoves()[x].getDamage());
  1485. }
  1486. }
  1487. }
  1488. System.out.println();
  1489. Thread.sleep(2000);
  1490.  
  1491. System.out.println(attPokemon.getName() + " now has " + attPokemon.getEXP() + " out of " + attPokemon.getMaxEXP() + " EXP to get from "
  1492. + "Level " + attPokemon.getLevel() + " to Level " + (attPokemon.getLevel()+1));
  1493. System.out.println("---------------------------");
  1494.  
  1495. }
  1496.  
  1497. public void calcEarnings(boolean isTrainer, int level) {
  1498. int ogEarnings = earnings;
  1499. if(isTrainer) {
  1500. int r = (int)(Math.random() * 30 + 1);
  1501. earnings += r * 10 * round;
  1502. } else {
  1503. int r = (int)(Math.random() * 20 + 1);
  1504. earnings += r * level;
  1505. }
  1506. System.out.println("\nEarnings increased from " + ogEarnings + " to " + earnings +"\n");
  1507. }
  1508.  
  1509. public static void removeParty(Pokemon party[]) {
  1510. for(int x = 0; x < 6; x++) {
  1511. party[x] = null;
  1512. }
  1513. }
  1514.  
  1515. public static void resetParty(Pokemon party[]) {
  1516. for(int pSlot = 0; pSlot < 6; pSlot++) {
  1517. if(party[pSlot] != null) {
  1518. party[pSlot].resetnHP();
  1519. for(int mSlot = 0; mSlot < 4; mSlot++) {
  1520. if(party[pSlot].getMoves()[mSlot] != null) {
  1521. party[pSlot].getMoves()[mSlot].resetnPP();
  1522. }
  1523. }
  1524. }
  1525. }
  1526. }
  1527.  
  1528. public static void reward(Pokemon myParty[], Pokemon oppParty[], ArrayList<Item> myBag) {
  1529. System.out.println("Congratulations on the victory!");
  1530. System.out.println("As a reward you get the option of either taking"
  1531. + " an opponent's Pokemon of your choosing or receiving a random item.");
  1532. System.out.println("\nDefeated Opponent's Party:");
  1533. printParty(oppParty, false);
  1534. boolean rewardChosen = false;
  1535. int userChoice = 0;
  1536. while(!rewardChosen) {
  1537. System.out.println("\n1: Add/Replace Pokemon");
  1538. System.out.println("2: Receive Random Item");
  1539.  
  1540. Scanner sc = new Scanner(System.in);
  1541. String userChoiceWord = sc.next();
  1542. if(userChoiceWord.toUpperCase().equals("Add/Replace Pokemon".toUpperCase())) {
  1543. userChoice = 1;
  1544. }
  1545. if(userChoiceWord.toUpperCase().equals("Receive Random Item".toUpperCase())) {
  1546. userChoice = 2;
  1547. }
  1548. if(userChoiceWord.equals("1")) {
  1549. userChoice = 1;
  1550. }
  1551. if(userChoiceWord.equals("2")) {
  1552. userChoice = 2;
  1553. }
  1554.  
  1555.  
  1556.  
  1557. if(userChoice == 1) {
  1558. rewardChosen = takeOppPokemon(myParty, oppParty, true);
  1559. }
  1560. if(userChoice == 2) {
  1561. rewardChosen = takeItem(myBag);
  1562. }
  1563. }
  1564. return;
  1565. }
  1566.  
  1567. public static boolean takeOppPokemon(Pokemon myParty[], Pokemon oppParty[], boolean isTrainer) {
  1568. boolean hasTaken = false;
  1569. while(!hasTaken) {
  1570.  
  1571. if(!isTrainer) {
  1572. for(int pSlot = 0; pSlot < 6; pSlot++) {
  1573. if(myParty[pSlot] == null) {
  1574. myParty[pSlot] = oppParty[0];
  1575. System.out.println(oppParty[0].getName() + " has been successfully added to your party.");
  1576. return true;
  1577. }
  1578. }
  1579. return replacePokemon(0, myParty, oppParty);
  1580. }
  1581. else {
  1582. printParty

Report this snippet  

You need to login to post a comment.