Question
Create the hangman game and implement it in a program. The players would be people using a GUI input. The game should validate that moves/turns follow the rules.You must use at least two of the concepts presented : queues, trees, stacks, sorts, or searches.
Explanation / Answer
// hangman.java import java.awt.*; import java.awt.event.*; import java.applet.*; public class hangman extends Applet implements ActionListener { //this is the used letter array private boolean usd[] = new boolean[26]; private String guessme; private int numguesses=0; private boolean finished = false; private boolean won = false; private Button a[]; public void init() { int i; StringBuffer buffer; // setLayout( new GridLayout( 2,13) ); a = new Button[26]; // create all 26 buttons for (i = 0; i =1 ) g.drawOval(82,95,30,30); g.setColor(Color.green); if (numguesses >=2 ) g.drawLine(97,125,97,150); if (numguesses >=3 ) g.drawLine(97,150,117,183); if (numguesses >=4 ) g.drawLine(97,150,77,183); if (numguesses >=5 ) g.drawLine(97,125,117,135); if (numguesses >=6 ) g.drawLine(97,125,77,135); StringBuffer st = new StringBuffer(); for (int l=0; l