Advertisement
Guest User

Untitled

a guest
May 19th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.16 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Application Five - HANGMAN
  4. // 5th Six Weeks
  5. //
  6. //-----------------------------------------------------------------------------
  7. //
  8. // Name:
  9. // Period:
  10. // Teacher:
  11. // Computer Science I-K
  12. //
  13. ///////////////////////////////////////////////////////////////////////////////
  14.  
  15. package BlackBox;
  16. import static java.lang.System.*;
  17. import java.io.*;
  18. import java.util.*;
  19. import java.awt.*;
  20. import javax.swing.*;
  21.  
  22.  
  23. public class App05
  24. {
  25. public static void main(String[] args) throws IOException
  26. {
  27. Game hangman = new Game();
  28. hangman.playGame();
  29. // hangman.setUp();
  30. // hangman.step();
  31.  
  32.  
  33. }
  34. }
  35.  
  36. class Game extends BlackBox
  37. {
  38.  
  39. //int x;
  40. //int y;
  41.  
  42.  
  43.  
  44.  
  45. private DataBase dBase;
  46. private boolean quit;
  47. private boolean reset;
  48. private String theWord;
  49. private boolean win;
  50. private boolean lose;
  51. private char theLetter;
  52. private int correctGuesses;
  53. private int wrongGuesses;
  54. private ArrayList<Character> usedLetters = new ArrayList<Character>();
  55.  
  56.  
  57.  
  58.  
  59. public Game() throws IOException
  60. {
  61. dBase = new DataBase();
  62. categoryBox.setText(dBase.getCategory());
  63. resetGameVariables();
  64. }
  65.  
  66.  
  67.  
  68. /*public void test()
  69. {
  70. out.println(dBase);
  71.  
  72. out.println("The category is " + dBase.getCategory());
  73. out.println("The word is " + dBase.getRandomWord());
  74. theWordBox.setText(dBase.getRandomWord());
  75. messageBox.setText("hi \n");
  76. messageBox.append("hi \n");
  77. messageBox.append("hi \n");
  78. usedLettersBox.setText("hi \n");
  79. scoreBox.setText("hi \n");
  80. letterBox.setText("hi \n");
  81. pen.setColor(Color.RED);
  82. pen.fillOval(100,100,20,40);
  83. pen.drawString("Bad things will happen here", 150, 50);
  84. repaint();
  85. } */
  86.  
  87.  
  88.  
  89. private void resetGameVariables()
  90. {
  91.  
  92. quit = false;
  93. reset = false;
  94. win = false;
  95. lose = false;
  96. usedLetters.clear();
  97. correctGuesses = 0;
  98. wrongGuesses = 0;
  99. theLetter = ' ';
  100.  
  101.  
  102. theWordBox.setText("");
  103. messageBox.setText("");
  104. usedLettersBox.setText("");
  105. scoreBox.setText("");
  106. letterBox.setText("");
  107. clearDrawingArea();
  108. }
  109.  
  110. public void playGame()
  111. {
  112.  
  113. while(!quit)
  114. {
  115. gameEngine();
  116. if(!reset && !quit)
  117. playAgain();
  118. }
  119.  
  120. exit(0);
  121.  
  122. // messageBox.setText("Done! Step 06 works! YEAH!");
  123. }
  124.  
  125.  
  126. private void gameEngine()
  127. {
  128.  
  129. resetGameVariables();
  130.  
  131. getTheWord();
  132. // theWordBox.setText(theWord);
  133. // messageBox.setText(dBase.toString());
  134. setup();
  135. if(!quit)
  136. showWordBlanks();
  137. showScore();
  138. while(!win && !lose && !quit && !reset)
  139. {
  140. if(theLetter != ' ')
  141. {
  142. processTheLetter();
  143. showScore();
  144. checkForWinner();
  145. animateGraphics();
  146. }
  147. delay(50);
  148. showResults();
  149. }
  150.  
  151.  
  152.  
  153. // pen.setColor(Color.red);
  154. // pen.drawString("Play game here.", 10, 25);
  155. // for(int x = 0; x< 100; x+= 20)
  156. // pen.drawString("Round" + x/20, 10, 50 + x);
  157. // repaint();
  158. }
  159.  
  160. private void checkForWinner()
  161. {
  162. win = (correctGuesses >= theWord.length());
  163. lose = (wrongGuesses >= 6);
  164. }
  165.  
  166.  
  167. private void showResults()
  168. {
  169. if(win)
  170. {
  171. JOptionPane.showMessageDialog
  172. (
  173. null,
  174. "Congratulations! You Win!",
  175. "Game Over",
  176. JOptionPane.INFORMATION_MESSAGE
  177.  
  178. );
  179. Winner();
  180. //Loser();
  181. }
  182.  
  183.  
  184. if(lose)
  185. {
  186. JOptionPane.showMessageDialog
  187. (
  188. null,
  189. "You Lose!\nThe Phrase was \"" + theWord + "\"",
  190. "Game Over",
  191. JOptionPane.INFORMATION_MESSAGE
  192.  
  193. );
  194.  
  195. Loser();
  196.  
  197. }
  198.  
  199. }
  200.  
  201.  
  202. private void animateGraphics()
  203. {
  204. switch(wrongGuesses)
  205. {
  206. case 1: part1(); break;
  207. case 2: part2(); break;
  208. case 3: part3(); break;
  209. case 4: part4(); break;
  210. case 5: part5(); break;
  211. case 6: part6(); break;
  212. }
  213. repaint();
  214. }
  215.  
  216.  
  217. void part1()
  218. {
  219.  
  220. Color skin = new Color(255,176,138);
  221. pen.setColor(skin);
  222. pen.fillOval(229,70,40,40);
  223. pen.setColor(Color.BLACK);
  224. pen.fillOval(236,83,5,5);
  225. pen.fillOval(252,83,5,5);
  226. pen.drawLine(242,101,251,101);
  227. Color brown = new Color(128,64,0);
  228. pen.setColor(brown);
  229. pen.fillOval(233,104,35,7);
  230. Color clothes = new Color(147,0,0);
  231. pen.setColor(clothes);
  232. //pen.fillRect(222,70,55,35);
  233. //pen.fillOval(210,69,35,35);
  234. //pen.fillOval(255,69,35,35);
  235. pen.fillOval(225,70,50,10);
  236. //pen.drawLine(250,40,230,80);
  237. //pen.drawLine(250,40,270,80);
  238.  
  239. Polygon tri = new Polygon();
  240. tri.addPoint(250,40);
  241. tri.addPoint(230,80);
  242. tri.addPoint(270,80);
  243.  
  244. pen.fill(tri);
  245.  
  246. //pen.drawString("WRONG ACTION ONE", 10, 50);
  247. }
  248.  
  249.  
  250. void part2()
  251. {
  252. Color cape = new Color(0,128,192);
  253. pen.setColor(cape);
  254. pen.fillRect(225,110,50,90);
  255.  
  256. Color cape2 = new Color(255,255,0);
  257. pen.setColor(cape2);
  258. pen.fillRect(225,190,50,8);
  259.  
  260. Color clothes = new Color(147,0,0);
  261. pen.setColor(clothes);
  262. pen.fillRect(238,110,25,45);
  263.  
  264. Color belt = new Color(128,64,0);
  265. pen.setColor(belt);
  266. pen.fillRect(238,140,25,6);
  267.  
  268. //pen.drawString("WRONG ACTION TWO", 10, 60);
  269. }
  270.  
  271.  
  272. void part3()
  273. {
  274.  
  275. Color skin = new Color(255,176,138);
  276. pen.setColor(skin);
  277. pen.drawLine(238,110,227,160);
  278. pen.fillOval(223,157,10,10);
  279. Color clothes = new Color(147,0,0);
  280. pen.setColor(clothes);
  281. pen.fillOval(219,106,25,10);
  282.  
  283.  
  284. //pen.drawString("WRONG ACTION THREE", 10, 70);
  285. }
  286.  
  287.  
  288. void part4()
  289. {
  290. Color staff = new Color(128,64,0);
  291. pen.setColor(staff);
  292. pen.fillRect(300,60,8,150);
  293.  
  294. Color skin = new Color(255,176,138);
  295. pen.setColor(skin);
  296. pen.drawLine(262,110,295,130);
  297. pen.fillOval(295,127,10,10);
  298. Color clothes = new Color(147,0,0);
  299. pen.setColor(clothes);
  300. pen.fillOval(257,106,25,10);
  301.  
  302.  
  303.  
  304. //pen.drawString("WRONG ACTION FOUR", 10, 80);
  305. }
  306.  
  307.  
  308. void part5()
  309. {
  310. pen.fillRect(239,150,10,50);
  311. pen.setColor(Color.BLACK);
  312. pen.fillOval(230,198,20,10);
  313.  
  314. //pen.drawString("WRONG ACTION FIVE", 10, 90);
  315. }
  316.  
  317.  
  318. void part6()
  319. {
  320. Color clothes = new Color(147,0,0);
  321. pen.setColor(clothes);
  322. pen.fillRect(253,150,10,50);
  323. pen.setColor(Color.BLACK);
  324. pen.fillOval(245,198,20,10);
  325. pen.drawArc(242,96,10,10,360,200);
  326.  
  327.  
  328.  
  329. }
  330.  
  331.  
  332. void Loser()
  333. {
  334. if(lose)
  335. {
  336. clearDrawingArea();
  337.  
  338. pen.clearRect(0,0,1000,1000);
  339.  
  340. pen.setColor(Color.BLACK);
  341. pen.fillRect(0,0,1000,1000);
  342.  
  343. Color green = new Color(128,255,0);
  344. Color orange = new Color(255,128,64);
  345. Color purple = new Color(128,0,255);
  346. pen.setColor(green);
  347. pen.drawLine(25,0,25,600);
  348. pen.setColor(purple);
  349. pen.drawLine(50,0,50,600);
  350. pen.setColor(orange);
  351. pen.drawLine(75,0,75,600);
  352. pen.setColor(green);
  353. pen.drawLine(100,0,100,600);
  354. pen.setColor(purple);
  355. pen.drawLine(125,0,125,600);
  356. pen.setColor(orange);
  357. pen.drawLine(150,0,150,600);
  358. pen.setColor(green);
  359. pen.drawLine(175,0,175,600);
  360. pen.setColor(purple);
  361. pen.drawLine(200,0,200,600);
  362. pen.setColor(orange);
  363. pen.drawLine(225,0,225,600);
  364. pen.setColor(green);
  365. pen.drawLine(250,0,250,600);
  366. pen.setColor(purple);
  367. pen.drawLine(275,0,275,600);
  368. pen.setColor(orange);
  369. pen.drawLine(300,0,300,600);
  370. pen.setColor(green);
  371. pen.drawLine(325,0,325,600);
  372. pen.setColor(purple);
  373. pen.drawLine(350,0,350,600);
  374. pen.setColor(orange);
  375. pen.drawLine(375,0,375,600);
  376. pen.setColor(green);
  377. pen.drawLine(400,0,400,600);
  378. pen.setColor(purple);
  379. pen.drawLine(425,0,425,600);
  380. pen.setColor(orange);
  381. pen.drawLine(450,0,450,600);
  382. pen.setColor(green);
  383. pen.drawLine(475,0,475,600);
  384. pen.setColor(purple);
  385. pen.drawLine(500,0,500,600);
  386. pen.setColor(orange);
  387. pen.drawLine(525,0,525,600);
  388. pen.setColor(green);
  389. pen.drawLine(550,0,550,600);
  390. pen.setColor(purple);
  391. pen.drawLine(575,0,575,600);
  392. pen.setColor(orange);
  393.  
  394. Color skin = new Color(255,176,138);
  395. pen.setColor(skin);
  396. pen.fillOval(229,70,40,40);
  397. pen.setColor(Color.BLACK);
  398. pen.drawLine(238,82,245,87);
  399. pen.drawLine(250,82,257,87);
  400. pen.drawLine(245,82,238,87);
  401. pen.drawLine(257,82,250,87);
  402. //pen.fillOval(236,83,5,5);
  403. //pen.fillOval(252,83,5,5);
  404. pen.drawLine(242,101,251,101);
  405. Color brown = new Color(128,64,0);
  406. pen.setColor(brown);
  407. pen.fillOval(233,104,35,7);
  408. // pen.setColor(clothes);
  409. //pen.fillRect(222,70,55,35);
  410. //pen.fillOval(210,69,35,35);
  411. //pen.fillOval(255,69,35,35);
  412. pen.fillOval(225,70,50,10);
  413. //pen.drawLine(250,40,230,80);
  414. //pen.drawLine(250,40,270,80);
  415. Polygon tri = new Polygon();
  416. tri.addPoint(250,40);
  417. tri.addPoint(230,80);
  418. tri.addPoint(270,80);
  419.  
  420. pen.fill(tri);
  421. Color cape = new Color(0,128,192);
  422. pen.setColor(cape);
  423. pen.fillRect(225,110,50,90);
  424. Color cape2 = new Color(255,255,0);
  425. pen.setColor(cape2);
  426. pen.fillRect(225,190,50,8);
  427.  
  428. // pen.setColor(clothes);
  429. pen.fillRect(238,110,25,45);
  430. Color belt = new Color(128,64,0);
  431. pen.setColor(belt);
  432. pen.fillRect(238,140,25,6);
  433.  
  434. pen.setColor(skin);
  435. pen.drawLine(238,110,227,160);
  436. pen.fillOval(223,157,10,10);
  437. // pen.setColor(clothes);
  438. pen.fillOval(219,106,25,10);
  439.  
  440. pen.setColor(skin);
  441. pen.drawLine(262,110,269,160);
  442. pen.fillOval(265,157,10,10);
  443. // pen.setColor(clothes);
  444. pen.fillOval(257,106,25,10);
  445.  
  446. pen.fillRect(239,150,10,50);
  447. pen.setColor(Color.BLACK);
  448. pen.fillOval(230,198,20,10);
  449.  
  450. // pen.setColor(clothes);
  451. pen.fillRect(253,150,10,50);
  452. pen.setColor(Color.BLACK);
  453. pen.fillOval(245,198,20,10);
  454. pen.drawArc(242,96,10,10,360,200);
  455.  
  456. repaint();
  457.  
  458. //pen.setBackgroundImage("gamevillage.jpg");
  459. }
  460.  
  461.  
  462.  
  463. //pen.drawString("WRONG ACTION SIX", 10, 100);
  464. }
  465.  
  466. void Winner()
  467. {
  468. if(win)
  469. {
  470. clearDrawingArea();
  471.  
  472. pen.clearRect(0,0,1000,1000);
  473.  
  474.  
  475. Color sky = new Color(7,182,248);
  476. pen.setColor(sky);
  477. pen.fillRect(0,0,1000,1000);
  478. Color grass = new Color(0,128,64);
  479. pen.setColor(grass);
  480. pen.fillRect(0,200,1000,1000);
  481.  
  482. Color yellow = new Color(255,255,0);
  483. pen.setColor(yellow);
  484. pen.fillOval(10,10,50,50);
  485.  
  486. Color cloud = new Color(255,255,255);
  487. pen.setColor(cloud);
  488. pen.fillOval(250,10,30,30);
  489. pen.fillOval(260,15,20,30);
  490. pen.fillOval(260,5,20,30);
  491. pen.fillOval(270,10,20,30);
  492. pen.fillOval(270,15,20,30);
  493. pen.fillOval(270,5,20,30);
  494. pen.fillOval(280,10,20,30);
  495. pen.fillOval(280,15,20,30);
  496. pen.fillOval(280,5,20,30);
  497. pen.fillOval(290,10,20,30);
  498.  
  499. pen.fillOval(380,20,30,30);
  500. pen.fillOval(390,25,20,30);
  501. pen.fillOval(390,15,20,30);
  502. pen.fillOval(400,20,20,30);
  503. pen.fillOval(400,25,20,30);
  504. pen.fillOval(400,15,20,30);
  505. pen.fillOval(410,20,20,30);
  506. pen.fillOval(410,25,20,30);
  507. pen.fillOval(420,15,20,30);
  508. pen.fillOval(420,20,20,30);
  509.  
  510. pen.setColor(Color.BLACK);
  511. pen.fillRect(70,100,100,100);
  512. pen.fillRect(250,100,200,100);
  513.  
  514. pen.setColor(Color.BLUE);
  515. pen.fillRect(80,130,20,20);
  516. pen.fillRect(370,130,20,20);
  517. pen.fillRect(300,130,20,20);
  518.  
  519. Color door = new Color(128,64,0);
  520. pen.setColor(door);
  521. pen.fillRect(130,159,25,40);
  522. pen.fillRect(400,159,25,40);
  523.  
  524. pen.setColor(Color.RED);
  525. Polygon roof1 = new Polygon();
  526. roof1.addPoint(120,50);
  527. roof1.addPoint(70,100);
  528. roof1.addPoint(170,100);
  529. pen.fill(roof1);
  530.  
  531. Polygon roof2 = new Polygon();
  532. roof2.addPoint(350,50);
  533. roof2.addPoint(250,100);
  534. roof2.addPoint(450,100);
  535. pen.fill(roof2);
  536.  
  537.  
  538. /*
  539. Color green = new Color(128,255,0);
  540. Color orange = new Color(255,128,64);
  541. Color purple = new Color(128,0,255);
  542. pen.setColor(green);
  543. pen.drawLine(25,0,25,600);
  544. pen.setColor(purple);
  545. pen.drawLine(50,0,50,600);
  546. pen.setColor(orange);
  547. pen.drawLine(75,0,75,600);
  548. pen.setColor(green);
  549. pen.drawLine(100,0,100,600);
  550. pen.setColor(purple);
  551. pen.drawLine(125,0,125,600);
  552. pen.setColor(orange);
  553. pen.drawLine(150,0,150,600);
  554. pen.setColor(green);
  555. pen.drawLine(175,0,175,600);
  556. pen.setColor(purple);
  557. pen.drawLine(200,0,200,600);
  558. pen.setColor(orange);
  559. pen.drawLine(225,0,225,600);
  560. pen.setColor(green);
  561. pen.drawLine(250,0,250,600);
  562. pen.setColor(purple);
  563. pen.drawLine(275,0,275,600);
  564. pen.setColor(orange);
  565. pen.drawLine(300,0,300,600);
  566. pen.setColor(green);
  567. pen.drawLine(325,0,325,600);
  568. pen.setColor(purple);
  569. pen.drawLine(350,0,350,600);
  570. pen.setColor(orange);
  571. pen.drawLine(375,0,375,600);
  572. pen.setColor(green);
  573. pen.drawLine(400,0,400,600);
  574. pen.setColor(purple);
  575. pen.drawLine(425,0,425,600);
  576. pen.setColor(orange);
  577. pen.drawLine(450,0,450,600);
  578. pen.setColor(green);
  579. pen.drawLine(475,0,475,600);
  580. pen.setColor(purple);
  581. pen.drawLine(500,0,500,600);
  582. pen.setColor(orange);
  583. pen.drawLine(525,0,525,600);
  584. pen.setColor(green);
  585. pen.drawLine(550,0,550,600);
  586. pen.setColor(purple);
  587. pen.drawLine(575,0,575,600);
  588. pen.setColor(orange);
  589. */
  590. Color skin = new Color(255,176,138);
  591. pen.setColor(skin);
  592. pen.fillOval(229,70,40,40);
  593.  
  594. pen.setColor(Color.BLACK);
  595. pen.fillOval(236,83,5,5);
  596. pen.fillOval(252,83,5,5);
  597. pen.drawArc(242,92,10,10,180,200);
  598. //pen.drawLine(242,101,251,101);
  599.  
  600. Color brown = new Color(128,64,0);
  601. pen.setColor(brown);
  602. pen.fillOval(233,104,35,7);
  603.  
  604. Color clothes = new Color(147,0,0);
  605. pen.setColor(clothes);
  606. //pen.fillRect(222,70,55,35);
  607. //pen.fillOval(210,69,35,35);
  608. //pen.fillOval(255,69,35,35);
  609. pen.fillOval(225,70,50,10);
  610. //pen.drawLine(250,40,230,80);
  611. //pen.drawLine(250,40,270,80);
  612.  
  613. Polygon tri = new Polygon();
  614. tri.addPoint(250,40);
  615. tri.addPoint(230,80);
  616. tri.addPoint(270,80);
  617. pen.fill(tri);
  618.  
  619. Color cape = new Color(0,128,192);
  620. pen.setColor(cape);
  621. pen.fillRect(225,110,50,90);
  622.  
  623. Color cape2 = new Color(255,255,0);
  624. pen.setColor(cape2);
  625. pen.fillRect(225,190,50,8);
  626.  
  627. pen.setColor(clothes);
  628. pen.fillRect(238,110,25,45);
  629.  
  630. Color belt = new Color(128,64,0);
  631. pen.setColor(belt);
  632. pen.fillRect(238,140,25,6);
  633.  
  634. pen.setColor(skin);
  635. pen.drawLine(238,110,227,160);
  636. pen.fillOval(223,157,10,10);
  637.  
  638. pen.setColor(clothes);
  639. pen.fillOval(219,106,25,10);
  640.  
  641. Color staff = new Color(128,64,0);
  642. pen.setColor(staff);
  643. pen.fillRect(300,60,8,150);
  644.  
  645. pen.setColor(skin);
  646. pen.drawLine(262,110,295,130);
  647. pen.fillOval(295,127,10,10);
  648. //pen.drawLine(262,110,269,160);
  649. //pen.fillOval(265,157,10,10);
  650.  
  651. pen.setColor(clothes);
  652. pen.fillOval(257,106,25,10);
  653.  
  654. pen.fillRect(239,150,10,50);
  655. pen.setColor(Color.BLACK);
  656. pen.fillOval(230,198,20,10);
  657.  
  658. pen.setColor(clothes);
  659. pen.fillRect(253,150,10,50);
  660. pen.setColor(Color.BLACK);
  661. pen.fillOval(245,198,20,10);
  662.  
  663.  
  664. repaint();
  665.  
  666. //pen.setBackgroundImage("gamevillage.jpg");*/
  667. }
  668.  
  669.  
  670.  
  671.  
  672. }
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682. private void getTheWord()
  683. {
  684.  
  685. theWord = dBase.getRandomWord();
  686. if(theWord == null)
  687. {
  688. JOptionPane.showMessageDialog
  689. (
  690. null,
  691. "No words available!",
  692. "CRITICAL ERROR!",
  693. JOptionPane.ERROR_MESSAGE
  694.  
  695. );
  696.  
  697. quit = true;
  698. }
  699. }
  700.  
  701.  
  702. void setup()
  703. {
  704.  
  705. pen.setColor(Color.BLACK);
  706. pen.fillRect(0,0,1000,1000);
  707. pen.setColor(Color.BLUE);
  708. pen.fillOval(100,180,300,60);
  709. pen.drawOval(74,171,350,100);
  710. pen.drawLine(30,0,72,220);
  711. pen.drawLine(100,0,142,258);
  712. pen.drawLine(65,0,105,200);
  713. pen.drawLine(145,0,180,200);
  714. pen.drawLine(195,0,230,200);
  715. pen.drawLine(470,0,422,219);
  716. pen.drawLine(435,0,397,189);
  717. pen.drawLine(400,0,352,256);
  718. pen.drawLine(367,0,322,176);
  719. pen.drawLine(327,0,282,176);
  720.  
  721. //Color magic = new Color(0,128,255,10);
  722. //pen.setColor(magic);
  723. //pen.fillRect(100,100,50,50);
  724.  
  725.  
  726.  
  727.  
  728.  
  729. /*
  730. Color blue = new Color(0,128,255);
  731. pen.setColor(blue);
  732. pen.fillRect(0,0,1000,1000);
  733. Color Green = new Color(0,128,0);
  734. pen.setColor(Green);
  735. pen.fillRect(0,290,700,200);
  736. Color yellow = new Color(255,255,0);
  737. pen.setColor(yellow);
  738. pen.fillOval(50,30,80,80);
  739. Color white = new Color(255,255,255);
  740. pen.setColor(white);
  741. pen.fillOval(280,35,50,50);
  742. pen.fillOval(295,25,50,50);
  743. pen.fillOval(295,45,50,50);
  744. pen.fillOval(315,35,50,50);
  745. pen.fillOval(325,25,50,50);
  746. pen.fillOval(325,45,50,50);
  747. pen.fillOval(345,35,50,50);
  748. pen.fillOval(345,45,50,50);
  749. pen.fillOval(345,25,50,50);
  750. pen.fillOval(365,35,50,50);
  751. Color Brown = new Color(128,64,0);
  752. pen.setColor(Brown);
  753. pen.drawLine(145,50,145,200);
  754. pen.drawLine(145,50,250,50);
  755. pen.drawLine(250,50,250,70);
  756. pen.setColor(Brown);
  757. pen.fillRect(125,200,200,50);
  758. pen.fillRect(45,240,350,10);
  759. pen.fillRect(60,240,10,70);
  760. pen.fillRect(370,240,10,70);
  761. */
  762.  
  763.  
  764. repaint();
  765. /*
  766.  
  767.  
  768. head()
  769. {
  770. pen.fillOval(100,100,100,100);
  771. }
  772.  
  773. body()
  774. {
  775. pen.fillRect(100,100,100,100);
  776. }
  777.  
  778. leftArm()
  779. {
  780. pen.drawLine(20,20,30,30);
  781. }
  782.  
  783. rightArm()
  784. {
  785. pen.fillLine(40,40,50,50);
  786. }
  787.  
  788. leftLeg()
  789. {
  790. pen.fillLine(70,70,80,80);
  791. }
  792.  
  793. rightLeg()
  794. {
  795. pen.fillRect(90,90,100,100);
  796. }
  797.  
  798.  
  799.  
  800. */
  801.  
  802.  
  803.  
  804.  
  805. }
  806.  
  807. private void playAgain()
  808. {
  809.  
  810. if(lose) // THIS WORKS
  811. {
  812. Loser();
  813. }
  814.  
  815. // THIS DOES NOT WORK YET, CHECK THE LOGICAL ORDER OF OCCURRENCE.
  816.  
  817. if(win)
  818. {
  819. Winner();
  820. }
  821.  
  822.  
  823.  
  824. int choice = JOptionPane.showConfirmDialog
  825. (
  826. null,
  827. "Do you want to play again?",
  828. "PLAY AGAIN?",
  829. JOptionPane.YES_NO_OPTION
  830.  
  831.  
  832. );
  833.  
  834. if(choice == JOptionPane.NO_OPTION)
  835. quit = true;
  836.  
  837.  
  838. }
  839.  
  840.  
  841. public void newGameAction()
  842. {
  843. //messageBox.setText("This is the new game action button");
  844.  
  845. reset = true;
  846. }
  847.  
  848.  
  849. public void showWordAction()
  850. {
  851. JOptionPane.showMessageDialog
  852. (
  853. null,
  854. "The word is " + theWord,
  855. "For Teacher Use Only!",
  856. JOptionPane.INFORMATION_MESSAGE
  857.  
  858. );
  859.  
  860. //messageBox.setText("This is the show word action button");
  861. }
  862.  
  863.  
  864. public void hintAction()
  865. {
  866. messageBox.setText("There are no hints in this game! Quit pushing this button! Dx");
  867. }
  868.  
  869.  
  870. public void exitAction()
  871. {
  872. quit = true;
  873. //messageBox.setText("This is the exit action button");
  874. }
  875.  
  876.  
  877. public void letterBoxAction()
  878. {
  879. String inputValue = letterBox.getText();
  880.  
  881. if(inputValue.length() != 1)
  882. {
  883. messageBox.setText("You did not enter a single letter \n");
  884. return;
  885. }
  886.  
  887. char possibleLetter = inputValue.charAt(0);
  888. possibleLetter= Character.toUpperCase(possibleLetter);
  889.  
  890. if(!Character.isLetter(possibleLetter))
  891. {
  892. messageBox.setText("Your choice is not the valid letter. \n");
  893. return;
  894. }
  895.  
  896. if(usedLetters.contains(possibleLetter))
  897. {
  898. messageBox.setText("That letter has already been used. \n");
  899. return;
  900. }
  901.  
  902. theLetter = possibleLetter;
  903. usedLetters.add(theLetter);
  904. Collections.sort(usedLetters);
  905. usedLettersBox.setText(usedLetters.toString());
  906. messageBox.setText("");
  907.  
  908.  
  909. //messageBox.setText("This is the letter box action button");
  910. }
  911.  
  912.  
  913. private void showWordBlanks()
  914. {
  915. String all = "";
  916. for(int x = 0; x < theWord.length(); x++)
  917.  
  918. if(Character.isLetter(theWord.charAt(x)))
  919. all += "-";
  920.  
  921. else
  922. {
  923. all += theWord.charAt(x);
  924. correctGuesses++;
  925. }
  926.  
  927. theWordBox.setText(all);
  928. }
  929.  
  930.  
  931. private void showScore()
  932. {
  933. scoreBox.setText("Correct Score: " + correctGuesses + "\n");
  934. scoreBox.append("Wrong Score: " + wrongGuesses + "\n");
  935. }
  936.  
  937.  
  938. private void processTheLetter()
  939. {
  940. boolean letterFound = false;
  941.  
  942. String userSolution = theWordBox.getText();
  943.  
  944. String all = "";
  945. for(int x = 0; x < theWord.length(); x++)
  946. if(Character.toUpperCase(theWord.charAt(x)) == theLetter)
  947. {
  948. letterFound = true;
  949. correctGuesses++;
  950. all += theWord.charAt(x);
  951. }
  952.  
  953. else
  954. all += userSolution.charAt(x);
  955.  
  956. if(!letterFound)
  957. wrongGuesses++;
  958.  
  959. theLetter = ' ';
  960. theWordBox.setText(all);
  961. }
  962.  
  963.  
  964. }
  965.  
  966.  
  967. class DataBase
  968. {
  969. private ArrayList<String> wordList = new ArrayList<String>();
  970. private String category;
  971.  
  972. public DataBase() throws IOException
  973. {
  974. String name = "words.dat";
  975.  
  976. Scanner fileScan = new Scanner(new File(name));
  977. category = fileScan.nextLine();
  978.  
  979. while(fileScan.hasNext())
  980. wordList.add(fileScan.nextLine());
  981.  
  982. }
  983.  
  984.  
  985. public String toString()
  986. {
  987. String all = "";
  988.  
  989. for(String data: wordList)
  990. all+= data + "\n";
  991. return all;
  992.  
  993. }
  994.  
  995.  
  996. public String getCategory()
  997. {
  998. return category;
  999. }
  1000.  
  1001.  
  1002. public String getRandomWord()
  1003. {
  1004. if(wordList.isEmpty())
  1005. return null;
  1006.  
  1007. int index = (int)(Math.random() * wordList.size());
  1008.  
  1009. String word = wordList.get(index);
  1010. wordList.remove(index);
  1011.  
  1012. return word;
  1013. }
  1014. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement