QuestionQuestion

For this assignment, you will create 4 command-line versions of the game ​Hangman. You should work alone on the project, start from scratch, and not view Hangman code of other students or found on-line.

Functional requirements
● The phrases for the game should be read in from a file (this code is given to you in starter code). The game chooses a random phrase from the list. This is the phrase the player tries to guess.
● The game generates a hidden phrase in which all letters in the phrase are replaced with asterisks. Spaces and punctuation-- all non-letters-- are left unhidden. So if the phrase is "Joe + Programmer", the initial partially hidden phrase is: *** + **********
● The user guesses a letter. All occurrences of the letter in the phrase are replaced in the partially hidden phrase. For our example, if the user guessed "o", the new partially hidden phrase would change to: * o * + ** o*******
● If a user guesses something that is not a letter (e.g., ‘%’) the user should be notified but not penalized a miss. Case should be ignored in terms of matching-- 'a' is the same as 'A'.
● If the guessed letter does not occur in the phrase, the user is notified of the miss and how many misses/chances are left.
● The user should NOT be penalized for guessing a previously correct or incorrect guess, but should be notified.
● If the user misses n times, the game is lost and the user should be notified. If all letters in the phrase are guessed, the user wins! You can set the number of guesses 'n' how you want.
● Provide a reasonable user interface such that the players is given instructions on how to play, the number of misses and previous misses are displayed, and it is clear how to proceed at each step. Test this out by performing a usability test with at least two people!

Style Requirements
Style your code using the ​Google Java Style Guidelines
For this first project, be sure and follow the ​formatting and ​naming guides.

Coding Specifications (all versions)
● Each time the program runs, choose a random phrase.
● Define the hidden phrase as a StringBuilder, because you will be changing it
as the game is played.
● Do not use static methods other than the main

Versions
You should create three versions of your solution. Complete each version before moving on to the next one.

version 1​: do not define other methods other than main.

version 2​: provide the following methods, but don't define any data members:
● randomPhrase -- returns a single phrase randomly chosen from a list
● generateHiddenPhrase -- returns the initial hidden phrase
● getGuess-- gets input from user and returns it.
● processGuess -- returns whether a letter matches and modifies the partially hidden phrase if there is a match.

Please use these exact method names along with appropriate parameters and, make it clear in your comments that you have done so.

version 3​: provide the same methods as in version 2, but also define data members for "phrase", "hiddenPhrase", and "previousGuesses". You will have fewer parameters in your methods for this version.

version 4:
Modify your version 3 so that the game plays the same but the player will be a bot.
* There is no user input-- when you run the app, it shows the bot's guesses and the system's feedback.
* You must have at least two classes in your app--Hangman and HangmanPlayer
*You can earn most of the points by creating a not that intelligent bot player, e.g., one that guesses 'a', then 'b', then 'c', and so on, until they win or lose. ​You are strongly encouraged to implement such a simple player first!

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class Hangman {

    public static void main(String[] args) {

       Hangman hangman = new Hangman();

       List<String> phraseList = null;
       // Get the phrase from a file of phrases
       try {
            phraseList = Files.readAllLines(Paths.get("phrases.txt"));
       } catch (IOException e) {
            System.out.println(e);
            System.exit(0);
       }

       /**
         * The phrases for the game should be read in from a file (this code is
         * given to you in starter code). The game chooses a random phrase from
         * the list. This is the phrase the player tries to guess.
         */
       String phrase = hangman.randomPhrase(phraseList);

       /**
         * The game generates a hidden phrase in which all letters in the phrase
         * are replaced with asterisks. Spaces and punctuation-- all
         * non-letters-- are left unhidden. So if the phrase is "Joe +
         * Programmer", the initial partially hidden phrase is: *** + **********
         */
       /**
         * Define the hidden phrase as a StringBuilder, because you will be
         * changing it as the game is played.
         */
       char ch;
       StringBuilder hiddenPhrase = hangman.generateHiddenPhrase(phrase);

       /**
         * If the user misses n times, the game is lost and the user should be
         * notified. If all letters in the phrase are guessed, the user wins!
         * You can set the number of guesses 'n' how you want.
         */
       int n = phrase.length() * 2 / 3;
       int miss = 0;

       // prepare for a simple comparison
       String guessedLetters = "";
       boolean isMissed;

       /**
         * Provide a reasonable user interface such that the players is given
         * instructions on how to play, the number of misses and previous misses...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$53.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats