For this assignment, you will create a command-line version of the game Hangman.
For this assignment you will research on StringBuilder Class (Use this link) and use it in your code.
Please finish the program in Java Language
Your game should have a list of at least ten phrases of your choosing (appropriate to all audiences please!) The game chooses a random phrase from the list. This is the phrase the player tries to guess. (10)
● The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation are left unhidden. So if the phrase is "Joe Programmer", the initial partially hidden phrase is: *** ********** (15)
● 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******* 15
● Allow the phrases and guesses to include lowercase and uppercase letters and digits. If a guess is not a letter or digit (e.g., ‘%’) the user should be notified but not penalized a miss. 10
● If the guessed letter does not occur in the phrase, the user is notified of the miss and how many misses/chances are left. 10
● The user should NOT be penalized for guessing a previously correct or incorrect guess, but should be notified. 10
● If the user misses 8 times, they lose and the game is over. If all letters in the phrase are guessed, the user wins! 10
● Provide a reasonable user interface such that the players is given instructions on how to play and it is clear how to proceed at each step. Test this out by performing a usability test with at least two people! 10
Coding Specifications
● Define the ten phrases as an array of Strings. ○ String phraseList[] = {"cats and dogs", "stephen curry"};
○ then phraseList[0] will give "cats and dogs" and phraseList[1] will give "stephen curry".
● Define the randomly chosen phrase as a String
● Define the hidden phrase as a StringBuilder, because you will be changing it as the game is played. ● You need not define other methods other than main
// Hangman.java : Java program to simulate the game of Hangman
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Hangman {
public static void main(String[] args) {
// array of 10 phrases
String phraseList[] = {"cats and dogs", "stephen curry", "twinkling eyes", "roses are red", "sharing is caring", "happy go lucky"
, "win some lose some", "all that shine is not gold", "life is good", "good morning"};
// maximum allowed attempts
int max_attempts = 8;
int attempts = 0; // number of wrong attempts
// list of guessed characters
ArrayList<Character> guessed_letters = new ArrayList<Character>();
char guess;
Scanner scan = new Scanner(System.in);
Random ran = new Random();
// randomly select a phrase
int index = ran.nextInt(phraseList.length);
// create the hidden phrase for display purpose
StringBuilder hidden = new StringBuilder();
for(int i=0;i<phraseList[index].length();i++)
{
if((phraseList[index].charAt(i) >='A' && phraseList[index].charAt(i) <='Z') ||
(phraseList[index].charAt(i) >='a' && phraseList[index].charAt(i) <='z') || (phraseList[index].charAt(i) >='0' && phraseList[index].charAt(i) <='9'))
hidden.append('*');
else
hidden.append(phraseList[index].charAt(i));
}
System.out.println("Welcome to Hangman game!!!");
System.out.println("The goal of the user is to guess the phrase selected by the computer.\n"
+ "At each step, the user guesses a letter( lowercase and uppercase letters and digits allowed) , the computer checks if the letter is present in the phrase or not.\n"
+ "If the letter is present, all occurrences of the letter is revealed else user is penalized for the guess.\nUser has a maximum of 8 attempts to guess the phrase ");
// loop that continues till all the attempts are exhausted or user has guessed the phrase
while(attempts < max_attempts)
{
System.out.println("\nHidden Phrase : "+hidden.toString());
System.out.println("Attempts Left : "+(max_attempts - attempts));
System.out.print("Enter a guess : ");
// input of guess
guess = scan.nextLine().charAt(0);
// check if guess is valid
if((guess >='A' && guess <='Z') ||
(guess >='a' && guess <='z') || ( guess >='0' && guess <='9'))
{
// check if this letter has already been guessed
if(guessed_letters.contains(guess))
{
System.out.println("You have already guessed this letter");
}else
{
guessed_letters.add(guess); // add to the guessed_letters list, if not guesses earlier
// check if phrase contains this letter, then update the hidden phrase
if(phraseList[index].contains(guess+""))
{
for(int i=0;i<phraseList[index].length();i++)
{
if(phraseList[index].charAt(i) == guess)
hidden.setCharAt(i, guess);
}
}else
{
attempts++; //else increase the number of attempts
System.out.println(guess+" not present in the phrase");
}
}
}else
{
System.out.println("Invalid guess. Valid letters are uppercase and lowercase letters and digits");
}
// check if user has guessed the phrase
if(hidden.toString().equals(phraseList[index]))
break;
}
// check if user had guessed the phrase or not at the end
if(hidden.toString().equals(phraseList[index]))
System.out.println("Congratulations!!! You won");
else
System.out.println("Sorry you lose!");
System.out.println("The phrase was : "+phraseList[index]);
scan.close();
}
}
//end of program
Output:


For this assignment, you will create a command-line version of the game Hangman. For this assignment...
JAVA Hangman Your game should have a list of at least ten phrases of your choosing.The game chooses a random phrase from the list. This is the phrase the player tries to guess. The phrase is hidden-- all letters are replaced with asterisks. Spaces and punctuation 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...
Overview In this exercise you are going to recreate the classic game of hangman. Your program will randomly pick from a pool of words for the user who will guess letters in order to figure out the word. The user will have a limited number of wrong guesses to complete the puzzle or lose the round. Though if the user answers before running out of wrong answers, they win. Requirements Rules The program will use 10 to 15 words as...
Hangman is a game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it by suggesting letters or numbers, within a certain number of guesses. You have to implement this game for Single Player, Where Computer (Your Program) will display a word with all characters hidden, which the player needed to be guessed. You have to maintain a dictionary of Words. One word will be selected by your program....
For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...
Please help with this Intro to programming in C
assignment!
Intro to Programming in C-Large Program 3 - Hangman Game Assignment purpose: User defined functions, character arrays, c style string member functions Write an interactive program that will allow a user to play the game of Hangman. You will need to: e You will use four character arrays: o one for the word to be guessed (solution) o one for the word in progress (starword) o one for all of...
c++
PROGRAM DESCRIPTION: In this assignment, you will be creating a memory matching game in C++. In this game, the user will need to match up the pairs symbols A,B,C,D,E on a 4x4 array. For example, the array could be initialized like the following: In this case, X represents an empty slot. The goal is for the user to match the A to the A, the B to the B, etc, until all pairs are matched up to win the...
Consider a class that could be used to play a game of hangman. The class has the following attributes: The secret word. The disguised word, in which each unknown letter in the secret word is replaced with a question mark (?). For example, if the secret word is abracadabra and the letters a, b, and e have been guessed, the disguised word would be ab?a?a?ab?a. The number of guesses made. The number of incorrect guesses. It will have the following...
Create the game hangman using c code: Program description In the game of hangman, one player picks a word, and the other player has to try to guess what the word is by selecting one letter at a time. If they select a correct letter, all occurrences of the letter are shown. If no letter shows up, they use up one of their turns. The player is allowed to use no more than 10 incorrect turns to guess what the...
Please create a Hangman game in Java language. For this game a random word will be selected from the following list (abstract, cemetery, nurse, pharmacy, climbing). You should keep a running tab of the user’s score and display it on screen; the user begins with 100 pts possible if they correctly guess the word without any mistakes. For every incorrect letter which is guessed, 10 pts should be taken away from what is left of their total possible points. For...
Original question IN JAVA Show the user a number of blank spaces equal to the number of letters in the word For cat, you would show _ _ _. Prompt a user to guess a letter until they have run out of guesses or guessed the full word By default, the user should be able to make 7 failed guesses before they lose the game. If the user guesses a letter that is in the target word, it does not...