Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Windows Program that plays a word guessing game of Hangman. For this ass

ID: 3637622 • Letter: W

Question

Write a Windows Program that plays a word guessing game of Hangman.

For this assignment, you are required to design and implement a user-friendly GUI using Java swing frames. This assignment mostly involves String processing. However, you are expected to use: formatting and commenting code, data validation, exception handling, modular design and hangman images to display the state and progress of the game.

Here are the requirements:

Computer picks a secret word that the user needs to guess. Use a fixed array of strings for a predetermined list of words (I will supply this)

Program displays as many dashes as there are letters in the secret word (let’s call this status indicator)

When the user guesses a letter, if that letter is in the secret word, all instances of that letter are filled in the status indicator. If this happens to be a failed guess, it is counted against the user, and, it is displayed in failed letter line (sorted). If the user guesses an already guessed letter, simply ignore it. Also, user can guess the entire word, if there is no match, this is counted as a guess. Don’t worry about displaying the incorrect word guesses.

Game ends when you user correctly guesses all letters in the secret word (successfully), or uses all 8 chances to guess a letter (hanged?).

Once the game ends, user should be able to restart a new game or exit.


Thank you all.

Explanation / Answer

import Gui; import java.io.*; import java.awt.*; import java.util.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; package hangman; public class Hangman { static final int MAXGUESS = 8; //max guesses per word static final int MAXLETTER = 'z' - 'a' + 1; //number of letters in alphabet static final String[] WORDS = {"apple", "banana", "cat", "dog", "elephant", "fish", "giraffe", "hippopotamus", "ice cream", "jelly", "kangaroo", "lion", "monkey", "noodles", "octopus", "parrot", "queen", "rabbit", "sun", "tree", "umbrella", "van", "window", "x-ray", "yellow", "zebra"}; //button stuff private JButton jbutton1, jbutton2, jbutton3; private StartNewHandler snHandler; private SolveHandler soHandler; //handlers and actionlisteners jbutton1 = new JButton("Start New"); snHandler = new StartNewHandler(); jbutton1.addActionListener(snHandler); jbutton2 = new JButton("Solve"); soHandler = new SolveHandler(); jbutton2.addActionListener(soHandler); public static void main(String[] args) { boolean again; // true while we play another game String answer; // users input System.out.println(" This is the word guessing game called Hangman."); System.out.println("The computer will pick a word and you must try to"); System.out.println("guess the letters in the word. If you guess the"); System.out.println("word with less than " + MAXGUESS + " mistakes, then you win!"); do { playGame(); //play one game of Hangman System.out.println(" Would you like to play another game? (YES OR NO)"); answer = Keyboard.readString(); if (answer.equalsIgnoreCase("yes")) again = true; else if (answer.equalsIgnoreCase("mo")) again = false; else { again = false; System.out.println("Your answer "" + answer + "" should be YES or NO."); } } while (again); System.out.println(" Thank you for playing Hangman!"); } //main end static void playGame() { boolean[] already; //if user already guessed these letters char c; // temporary variable for a character boolean[] display; //if we display each letter in word int found; //how many times we find user's guess int i; //temporary variable for index loop char inputChar; // users input (as one character) String inputString; //users input (as a string) int length; //length of our random word int letters; //actual letters in word (not " " or "-") int mistakes; //number of mistakes boolean playing; //true while we are playing game String word; //our random word from WORDS list mistakes = 0; //start with no mistakes //Pick a random word from WORDS list. word = WORDS [(int)(Math.random() * WORDS.length)]; // System.out.println("debug: word = ' " + word + "'"); length = word.length(); //get length of random word //Create a display array to decide if we display a letter in the word display = new boolean[length]; letters = 0; //actual letters in word for (i=0; i = 'a') && (c
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote