Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.59 KB | None | 0 0
  1. package group.project;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.util.Random;
  7. import javax.swing.*;
  8.  
  9. public class GroupProject
  10. {
  11. JFrame window;
  12. Container con;
  13. JPanel titlePanel, startButtonPanel, mainTextPanel, choiceButtonPanel, playerPanel;
  14. JLabel titleLabel, hpLabel, hpLabelNumber, experienceLabel, experienceNumberLabel;
  15. JButton startButton, choice1, choice2, choice3, choice4;
  16. JTextArea mainTextArea;
  17.  
  18. Font titleFont = new Font("Comic Sans MS Bold", Font.PLAIN, 70);
  19. Font titleFontS = new Font("Comic Sans MS Bold", Font.PLAIN, 47);
  20. Font startFont = new Font("Impact", Font.PLAIN, 40);
  21. Font textFont = new Font ("Times New Roman Bold", Font.PLAIN, 20);
  22. Font textFontS = new Font ("Times New Roman Bold", Font.PLAIN, 15);
  23. Font buttonFont = new Font ("Times New Roman Bold", Font.PLAIN, 40);
  24. Font buttonFontS = new Font ("Times New Roman Bold", Font.PLAIN, 27);
  25. Font buttonFontES = new Font ("Times New Roman Bold", Font.PLAIN, 20);
  26.  
  27. int currentPlayerHP = 10;
  28. int totalPlayerHP = 10;
  29. int currentPlayerXP = 0;
  30. int totalPlayerXP = 50;
  31. int enemyPokemonNum1;
  32. int enemyPokemonNum2;
  33. int enemyPokemonNum3;
  34. int playerLevel = 0;
  35. int enemyPokemonMaxHP;
  36. int enemyPokemonCurrentHP;
  37.  
  38. String position;
  39. String pokemonType;
  40.  
  41. TitleScreenHandler titleHandler = new TitleScreenHandler();
  42. ChoiceHandler choiceHandler = new ChoiceHandler();
  43. // Item smallPotion = new Item("small potion", 0);
  44. // Item mediumPotion = new Item("medium potion", 0);
  45.  
  46. public GroupProject()
  47. {
  48. window = new JFrame();
  49. window.setSize(600, 800);
  50. window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  51. window.getContentPane().setBackground(Color.darkGray);
  52. window.setLayout(null);
  53. window.setVisible(true);
  54. con = window.getContentPane();
  55.  
  56. titlePanel = new JPanel();
  57. titlePanel.setBounds(50,75,500,100);
  58. titlePanel.setBackground(Color.darkGray);
  59. titleLabel = new JLabel("POKÉ ARENA");
  60. titleLabel.setForeground(Color.white);
  61. titleLabel.setFont(titleFont);
  62.  
  63. startButtonPanel = new JPanel();
  64. startButtonPanel.setBounds(150, 500, 300, 150);
  65. startButtonPanel.setBackground(Color.darkGray);
  66.  
  67. startButton = new JButton("START");
  68. startButton.setBackground(Color.darkGray);
  69. startButton.setForeground(Color.white);
  70. startButton.setFont(startFont);
  71. startButton.addActionListener(titleHandler);
  72. startButton.setFocusPainted(false);
  73.  
  74. titlePanel.add(titleLabel);
  75. startButtonPanel.add(startButton);
  76.  
  77. con.add(titlePanel);
  78. con.add(startButtonPanel);
  79. }
  80.  
  81. public void createScreen()
  82. {
  83. titlePanel.setVisible(false);
  84. startButtonPanel.setVisible(false);
  85.  
  86. mainTextPanel = new JPanel();
  87. mainTextPanel.setBounds(125,150,350,350);
  88. mainTextPanel.setBackground(Color.gray);
  89. mainTextPanel.setBorder(BorderFactory.createLineBorder(Color.black, 2, true));
  90. con.add(mainTextPanel);
  91.  
  92. mainTextArea = new JTextArea();
  93. mainTextArea.setBounds(100,100,300,325);
  94. mainTextArea.setBackground(Color.gray);
  95. mainTextArea.setForeground(Color.white);
  96. mainTextArea.setFont(textFontS);
  97. mainTextArea.setLineWrap(true);
  98. mainTextArea.setWrapStyleWord(true);
  99. mainTextArea.setEditable(false);
  100. mainTextPanel.add(mainTextArea);
  101.  
  102. choiceButtonPanel = new JPanel();
  103. choiceButtonPanel.setBounds(100, 500, 400, 200);
  104. choiceButtonPanel.setBackground(Color.darkGray);
  105. con.add(choiceButtonPanel);
  106.  
  107. choice1 = new JButton("Choice 1");
  108. choice1.setBackground(Color.darkGray);
  109. choice1.setForeground(Color.white);
  110. choice1.setFont(buttonFont);
  111. choice1.setPreferredSize(new Dimension(150,60));
  112. choiceButtonPanel.add(choice1);
  113. choice1.setFocusPainted(false);
  114. choice1.addActionListener(choiceHandler);
  115. choice1.setActionCommand("c1");
  116.  
  117. choice2 = new JButton("Choice 2");
  118. choice2.setBackground(Color.darkGray);
  119. choice2.setForeground(Color.white);
  120. choice2.setFont(buttonFontS);
  121. choice2.setPreferredSize(new Dimension(150,60));
  122. choiceButtonPanel.add(choice2);
  123. choice2.setFocusPainted(false);
  124. choice2.addActionListener(choiceHandler);
  125. choice2.setActionCommand("c2");
  126.  
  127. choice3 = new JButton("Choice 3");
  128. choice3.setBackground(Color.darkGray);
  129. choice3.setForeground(Color.white);
  130. choice3.setFont(buttonFont);
  131. choice3.setPreferredSize(new Dimension(150,60));
  132. choiceButtonPanel.add(choice3);
  133. choice3.setFocusPainted(false);
  134. choice3.addActionListener(choiceHandler);
  135. choice3.setActionCommand("c3");
  136.  
  137. playerPanel = new JPanel();
  138. playerPanel.setBounds(100,10,400,50);
  139. playerPanel.setBackground(Color.gray);
  140. playerPanel.setLayout(new GridLayout(1,4));
  141. playerPanel.setBorder(BorderFactory.createLineBorder(Color.black, 2, true));
  142. con.add(playerPanel);
  143.  
  144. hpLabel = new JLabel("HP: ");
  145. hpLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  146. hpLabel.setFont(textFont);
  147. hpLabel.setForeground(Color.white);
  148. playerPanel.add(hpLabel);
  149.  
  150. hpLabelNumber = new JLabel();
  151. hpLabelNumber.setFont(textFont);
  152. hpLabelNumber.setForeground(Color.white);
  153. playerPanel.add(hpLabelNumber);
  154.  
  155. experienceLabel = new JLabel("EXP: ");
  156. experienceLabel.setHorizontalAlignment(SwingConstants.RIGHT);
  157. experienceLabel.setFont(textFont);
  158. experienceLabel.setForeground(Color.white);
  159. playerPanel.add(experienceLabel);
  160.  
  161. experienceNumberLabel = new JLabel();
  162. experienceNumberLabel.setFont(textFont);
  163. experienceNumberLabel.setForeground(Color.white);
  164. playerPanel.add(experienceNumberLabel);
  165.  
  166. playerSetup();
  167. openingCeremony();
  168. }
  169.  
  170. public void playerSetup()
  171. {
  172. experienceNumberLabel.setText(currentPlayerXP + "/" + totalPlayerXP);
  173. hpLabelNumber.setText(currentPlayerHP + "/" + totalPlayerHP);
  174. }
  175.  
  176. public void openingCeremony()
  177. {
  178. position = "openingCeremony";
  179.  
  180. mainTextArea.setText("You stand amongst your fellow rivals"
  181. + " waiting your turn to come to finally "
  182. + "beat these sorry excuses for men into the "
  183. + "ground! However... you don't techniqually "
  184. + "have a pokemon yet... BUT ALAS! They sell "
  185. + "some at the general store. AWAYYYY!\n\n"
  186. + "=================================\n"
  187. + "\"Hello sir, can you please choose your desired "
  188. + "pokemon to fight with?\"\n\n"
  189. + "What a wretched wench she is INDEED!\n"
  190. + "=================================\n\n"
  191. + "Well, which Pokemon do you DESIRE?");
  192.  
  193.  
  194. choice1.setText("Charmander");
  195. choice1.setFont(buttonFontES);
  196. choice2.setText("Bulbasaur");
  197. choice2.setFont(buttonFontES);
  198. choice3.setText("Squirtle");
  199. choice3.setFont(buttonFontES);
  200. }
  201.  
  202. public void charmanderChosen()
  203. {
  204. pokemonDecider();
  205. position = "charmanderChosen";
  206. pokemonType = "Charmander";
  207.  
  208. mainTextArea.setFont(titleFontS);
  209. mainTextArea.setText("Charmander\n"
  210. + " HAS\n"
  211. + " BEEN\n"
  212. + " CHOSEN!!!");
  213.  
  214.  
  215. choice1.setText("");
  216. choice1.setVisible(false);
  217. choice2.setText("");
  218. choice2.setVisible(false);
  219. choice3.setText("Continue...");
  220. choice3.setFont(buttonFontES);
  221. choice3.setVisible(true);
  222. }
  223.  
  224. public void bulbasaurChosen()
  225. {
  226. pokemonDecider();
  227. position = "bulbasaurChosen";
  228. pokemonType = "bulbasaur";
  229.  
  230. mainTextArea.setFont(titleFontS);
  231. mainTextArea.setText("BULBASAUR\n"
  232. + " HAS\n"
  233. + " BEEN\n"
  234. + " CHOSEN!!!");
  235.  
  236. choice1.setText("");
  237. choice1.setVisible(false);
  238. choice2.setText("");
  239. choice2.setVisible(false);
  240. choice3.setText("Continue...");
  241. choice3.setFont(buttonFontES);
  242. choice3.setVisible(true);
  243. }
  244.  
  245. public void squirtleChosen()
  246. {
  247. pokemonDecider();
  248. position = "squirtleChosen";
  249. pokemonType = "Squirtle";
  250.  
  251. mainTextArea.setFont(titleFontS);
  252. mainTextArea.setText("Squirtle\n"
  253. + " HAS\n"
  254. + " BEEN\n"
  255. + " CHOSEN!!!");
  256.  
  257. choice1.setText("");
  258. choice1.setVisible(false);
  259. choice2.setText("");
  260. choice2.setVisible(false);
  261. choice3.setText("Continue...");
  262. choice3.setFont(buttonFontES);
  263. choice3.setVisible(true);
  264. }
  265.  
  266. public void pokemonDecider()
  267. {
  268. position = "pokemonDecider";
  269.  
  270. int[] enemy1 = {1,2,3};
  271. Random random1 = new Random();
  272.  
  273. int[] enemy2 = {4,5,6};
  274. Random random2 = new Random();
  275.  
  276. int[] enemy3 = {7,8,9};
  277. Random random3 = new Random();
  278.  
  279. enemyPokemonNum1 = random1.nextInt(enemy1.length);
  280. enemyPokemonNum2 = random2.nextInt(enemy2.length);
  281. enemyPokemonNum3 = random3.nextInt(enemy3.length);
  282. }
  283.  
  284. public void firstBattleMessage()
  285. {
  286. position = "firstBattleMessage";
  287.  
  288. String enemyPokemon;
  289.  
  290. switch (enemyPokemonNum1) {
  291. case 1:
  292. enemyPokemon = "Magikarp";
  293. enemyPokemonMaxHP = 10;
  294. enemyPokemonCurrentHP = enemyPokemonMaxHP; break;
  295. case 2:
  296. enemyPokemon = "Metapod";
  297. enemyPokemonMaxHP = 15;
  298. enemyPokemonCurrentHP = enemyPokemonMaxHP; break;
  299. default:
  300. enemyPokemon = "Slaking";
  301. enemyPokemonMaxHP = 15;
  302. enemyPokemonCurrentHP = enemyPokemonMaxHP; break;
  303. }
  304.  
  305. mainTextArea.setFont(textFontS);
  306. mainTextArea.setText(
  307. "=================================\n"
  308. + "Your challenger brought forth " + enemyPokemon + "!\n"
  309. + "=================================\n\n\n\n");
  310.  
  311. // switch (enemyPokemonNum1) {
  312. // case 1:
  313. // mainTextArea.setText(
  314. // "=================================\n"
  315. // + "Your challenger brought forth " + enemyPokemon + "!\n"
  316. // + "=================================\n\n\n\n");
  317. // }
  318.  
  319. choice1.setText("");
  320. choice1.setVisible(false);
  321. choice2.setText("");
  322. choice2.setVisible(false);
  323. choice3.setText("Continue...");
  324. choice3.setFont(buttonFontES);
  325. choice3.setVisible(true);
  326. }
  327.  
  328. public void firstBattle()
  329. {
  330. position = "firstBattle";
  331. String enemyPokemon;
  332. String pokemonAttack;
  333.  
  334. switch (enemyPokemonNum1) {
  335. case 1:
  336. enemyPokemon = "Magikarp";
  337. pokemonAttack = "Splash";
  338. break;
  339. case 2:
  340. enemyPokemon = "Metapod";
  341. pokemonAttack = "Harden";
  342. break;
  343. default:
  344. enemyPokemon = "Slaking";
  345. pokemonAttack = "Loaf Around";
  346. break;
  347. }
  348.  
  349. mainTextArea.setFont(textFontS);
  350. mainTextArea.setText(
  351. "=================================\n"
  352. + "Enemy " + enemyPokemon + " used " + pokemonAttack + "!!!\n\n"
  353. + "...... IT HAD NO EFFECT!\n\n"
  354. + "=================================\n"
  355. + "Your turn to fight back!!\n"
  356. + "=================================\n\n\n"
  357. + "... choose your option.");
  358.  
  359. choice1.setText("Attack");
  360. choice1.setVisible(true);
  361. choice1.setFont(buttonFontS);
  362. choice2.setText("Inventory");
  363. choice2.setFont(buttonFontES);
  364. choice2.setVisible(true);
  365. choice3.setText("Run");
  366. choice3.setFont(buttonFontS);
  367. choice3.setVisible(true);
  368. }
  369.  
  370. public void pokemonAttacks()
  371. {
  372. position = "pokemonAttacks";
  373.  
  374. if (playerLevel < 2)
  375. {
  376. mainTextArea.setText(
  377. "\n"
  378. + "=================================\n"
  379. + "So far you have but ONE attack!\n"
  380. + "CHOOSE WHICH ATTACK YOU WILL USE!!!\n"
  381. + "=================================\n\n"
  382. + "|--------------------------------------------|\n"
  383. + "| Tackle -- Just a teenie attack, |\n"
  384. + "| but good enough. |\n"
  385. + "|--------------------------------------------|\n");
  386.  
  387. choice1.setText("Tackle");
  388. choice1.setFont(buttonFontS);
  389. choice1.setVisible(true);
  390. choice2.setText("");
  391. choice2.setFont(buttonFontS);
  392. choice2.setVisible(false);
  393. choice3.setText("Back");
  394. choice3.setFont(buttonFontS);
  395. choice3.setVisible(true);
  396. }
  397.  
  398. else if (playerLevel >= 2 && playerLevel <= 3)
  399. {
  400. mainTextArea.setText(
  401. "\n"
  402. + "=================================\n"
  403. + "You now have TWOOOO attacks!\n"
  404. + "CHOOSE WHICH ATTACK YOU WILL USE!!!\n"
  405. + "=================================\n\n"
  406. + "|--------------------------------------------|\n"
  407. + "| Tackle -- Just a teenie attack, |\n"
  408. + "| but good enough. |\n"
  409. + "|--------------------------------------------|\n"
  410. + "| Quick Attack -- A bit stronger |\n"
  411. + "| but has a chance to miss. |\n"
  412. + "|--------------------------------------------|\n");
  413.  
  414. choice1.setText("Tackle");
  415. choice1.setFont(buttonFontS);
  416. choice1.setVisible(true);
  417. choice2.setText("Quick Attack");
  418. choice2.setFont(buttonFontES);
  419. choice2.setVisible(true);
  420. choice3.setText("Back");
  421. choice3.setFont(buttonFontS);
  422. choice3.setVisible(true);
  423. }
  424.  
  425. else
  426. {
  427. mainTextArea.setText(
  428. "\n"
  429. + "Player Level too high.");
  430. }
  431. }
  432.  
  433. public void tackleBattleMessage()
  434. {
  435. position = "tackleBattleMessage";
  436.  
  437. String enemyPokemon;
  438.  
  439. switch (enemyPokemonNum1) {
  440. case 1:
  441. enemyPokemon = "Magikarp"; break;
  442. case 2:
  443. enemyPokemon = "Metapod"; break;
  444. default:
  445. enemyPokemon = "Slaking"; break;
  446. }
  447.  
  448. enemyPokemonCurrentHP -= 5;
  449.  
  450. if (enemyPokemonCurrentHP > 0)
  451. {
  452. mainTextArea.setText(
  453. "\n"
  454. + "=================================\n"
  455. + "Your tackle was VERY effective!\n"
  456. + "=================================\n"
  457. + "You dealt 5 damage to the enemy " + enemyPokemon + ".\n\n"
  458. + "Enemy " + enemyPokemon + " is now at " + enemyPokemonCurrentHP + "/" + enemyPokemonMaxHP + "HP");
  459.  
  460. choice1.setText("Continue...");
  461. choice1.setFont(buttonFontES);
  462. choice1.setVisible(true);
  463. choice2.setText("");
  464. choice2.setVisible(false);
  465. choice3.setText("");
  466. choice3.setVisible(false);
  467. }
  468. else
  469. {
  470. mainTextArea.setText(
  471. "\n"
  472. + "=================================\n"
  473. + "You've KILLED the enemy " + enemyPokemon + "!!!\n"
  474. + "=================================\n\n"
  475. + "You've gained 25 Experience Points!\n"
  476. + "YEEAAHH!\n"
  477. + "=================================\n"
  478. + "You've ALSO gained 1 Small Potion!!!\n"
  479. + "OH BABY!!!\n"
  480. + "=================================\n");
  481.  
  482. currentPlayerXP = currentPlayerXP + 25;
  483.  
  484. playerSetup();
  485.  
  486. choice1.setText("");
  487. choice1.setVisible(false);
  488. choice2.setText("Continue...");
  489. choice2.setFont(buttonFontES);
  490. choice2.setVisible(true);
  491. choice3.setText("");
  492. choice3.setVisible(false);
  493. }
  494. }
  495.  
  496. public void inventoryMenu()
  497. {
  498. position = "inventoryMenu";
  499.  
  500. mainTextArea.setText(
  501. "\n\n\n\n"
  502. + "IT'S EMPTY YOU FOOOOOOLLLL!!!!!");
  503.  
  504. choice1.setText("Back");
  505. choice1.setFont(buttonFontS);
  506. choice2.setText("");
  507. choice2.setVisible(false);
  508. choice3.setText("");
  509. choice3.setVisible(false);
  510. }
  511.  
  512. public void runOption()
  513. {
  514. position = "runOption";
  515.  
  516. mainTextArea.setText(
  517. "\n\n\n\n"
  518. + "YOU THINK YOU CAN RUUNNN?!?! THINK AGAAIN\n\n"
  519. + "AAAAHAHAHAHAHAHAAAAAAA");
  520.  
  521. choice1.setText("Back");
  522. choice1.setFont(buttonFontS);
  523. choice2.setText("");
  524. choice2.setVisible(false);
  525. choice3.setText("");
  526. choice3.setVisible(false);
  527. }
  528.  
  529. public class TitleScreenHandler implements ActionListener
  530. {
  531. @Override
  532. public void actionPerformed(ActionEvent e)
  533. {
  534. createScreen();
  535. }
  536. }
  537.  
  538. public class ChoiceHandler implements ActionListener
  539. {
  540. @Override
  541. public void actionPerformed(ActionEvent event)
  542. {
  543. String yourChoice = event.getActionCommand();
  544.  
  545. switch(position)
  546. {
  547. case "openingCeremony":
  548. switch(yourChoice)
  549. {
  550. case "c1": charmanderChosen(); break;
  551. case "c2": bulbasaurChosen(); break;
  552. case "c3": squirtleChosen(); break;
  553. }
  554. break;
  555. case "charmanderChosen":
  556. switch(yourChoice)
  557. {
  558. case "c3": firstBattleMessage(); break;
  559. }
  560. break;
  561. case "bulbasaurChosen":
  562. switch(yourChoice)
  563. {
  564. case "c3": firstBattleMessage(); break;
  565. }
  566. break;
  567. case "squirtleChosen":
  568. switch(yourChoice)
  569. {
  570. case "c3": firstBattleMessage(); break;
  571. }
  572. break;
  573. case "firstBattleMessage":
  574. switch(yourChoice)
  575. {
  576. case "c3": firstBattle(); break;
  577. }
  578. break;
  579. case "firstBattle":
  580. switch(yourChoice)
  581. {
  582. case "c1": pokemonAttacks(); break;
  583. case "c2": inventoryMenu(); break;
  584. case "c3": runOption(); break;
  585. }
  586. break;
  587. case "inventoryMenu":
  588. switch(yourChoice)
  589. {
  590. case "c1": firstBattle(); break;
  591. }
  592. break;
  593. case "runOption":
  594. switch(yourChoice)
  595. {
  596. case "c1": firstBattle(); break;
  597. }
  598. break;
  599. case "pokemonAttacks":
  600. switch(yourChoice)
  601. {
  602. case "c1": tackleBattleMessage(); break;
  603. case "c2": break;
  604. case "c3": firstBattle(); break;
  605. }
  606. break;
  607. case "tackleBattleMessage":
  608. switch(yourChoice)
  609. {
  610. case "c1": firstBattle(); break;
  611. case "c2": break;
  612. case "c3": break;
  613. }
  614. }
  615. }
  616. }
  617. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement