hey dear
i just need help with update my code i have the hangman program
i just want to draw the body of hang man when the player lose every
attempt program is going to draw the body of hang man until the
player lose all his/her all attempts and hangman be hanged and show
in the display
you can write the program in java language:
this is the code bellow:
import java.util.Random;
import java.util.Scanner;
public class Hangmann {
// helper method to generate a String containing n number of '*' characters
static String generateAsteriskString(int n) {
String s = "";
// looping and appending n number of '*'s to s
for (int i = 0; i < n; i++) {
s += "*";
}
return s;
}
// helper method to make char represented by c visible in hidden string if
// it exist on secret word
static String replace(String secret, String hidden, char c) {
String s = "";
// looping through secret string
for (int i = 0; i < secret.length(); i++) {
// if current char in secret word is same as c, appending c to
// result String
if (secret.charAt(i) == c) {
s += c;
} else {
// otherwise appending what hidden word already had in this
// position to result String
s += hidden.charAt(i);
}
}
// returning result String
return s;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// creating an array of words
String[] words = { "write", "that", "program", "java", "friend", "cool" };
// random number generator
Random random = new Random();
// maximum attempts (missed attempts) per word
int MAX_ATTEMPTS = 8;
String ch = "y";
// looping until user choose to quit
while (ch.equalsIgnoreCase("y")) {
// generating a random index between 0 and words.length-1, taking
// word at this index as the secret word
String secretword = words[random.nextInt(words.length)];
// initializing number of misses to 0
int misses = 0;
// creating a String of same length containing asterisks, as hidden
// word
String hidden = generateAsteriskString(secretword.length());
// looping until hidden and secret word are same or until all
// attempts are exhausted
while (!hidden.equals(secretword) && misses < MAX_ATTEMPTS) {
// asking and reading a letter
System.out.print("(Guess) Enter a letter in word " + hidden
+ " > ");
// reading a word, converting to lower case, taking first
// character
char letter = scanner.next().toLowerCase().charAt(0);
// checking if this character is already made visible (exist on
// hidden)
if (hidden.contains("" + letter)) {
System.out.println("\t" + letter
+ " is already in the word");
}
// checking if this character is not in secret word
else if (!secretword.contains("" + letter)) {
System.out.println("\t" + letter + " is not in the word");
misses++; // its a miss
} else {
// otherwise updating hidden word by calling replace method
hidden = replace(secretword, hidden, letter);
}
}
// displaying word and misses.
// using 'time' instead of 'times' if misses equals 1 (singular
// form)
if (misses == MAX_ATTEMPTS) {
System.out
.println("Sorry! You could not guess the word. You missed "
+ MAX_ATTEMPTS
+ " attempts, the word was "
+ secretword);
} else if (misses == 1) {
System.out.println("The word is " + secretword
+ ". You missed " + misses + " time");
} else {
System.out.println("The word is " + secretword
+ ". You missed " + misses + " times");
}
// asking and reading user choice whether to continue or not
System.out
.print("Do you want to guess another word? Enter y or n> ");
ch = scanner.next();
}
}
}
drawing it means only give a shape to hangman it means give a picture of hangman or design
here i modify the code and add Jframe to show the picture of hangman after attempts Max times . and miss word every time the oops.png is showing ..
here is the code ---
import java.util.Random;
import javax.swing.*;
import java.util.Scanner;
public class Hangmann {
// helper method to generate a String containing n number of '*' characters
static String generateAsteriskString(int n) {
String s = "";
// looping and appending n number of '*'s to s
for (int i = 0; i < n; i++) {
s += "*";
}
return s;
}
// helper method to make char represented by c visible in hidden string if
// it exist on secret word
static String replace(String secret, String hidden, char c) {
String s = "";
// looping through secret string
for (int i = 0; i < secret.length(); i++) {
// if current char in secret word is same as c, appending c to
// result String
if (secret.charAt(i) == c) {
s += c;
} else {
// otherwise appending what hidden word already had in this
// position to result String
s += hidden.charAt(i);
}
}
// returning result String
return s;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// creating an array of words
String[] words = { "write", "that", "program", "java", "friend", "cool" };
// random number generator
Random random = new Random();
// maximum attempts (missed attempts) per word
int MAX_ATTEMPTS = 8;
String ch = "y";
// looping until user choose to quit
while (ch.equalsIgnoreCase("y")) {
// generating a random index between 0 and words.length-1, taking
// word at this index as the secret word
String secretword = words[random.nextInt(words.length)];
// initializing number of misses to 0
int misses = 0;
// creating a String of same length containing asterisks, as hidden
// word
String hidden = generateAsteriskString(secretword.length());
// looping until hidden and secret word are same or until all
// attempts are exhausted
while (!hidden.equals(secretword) && misses < MAX_ATTEMPTS) {
// asking and reading a letter
System.out.print("(Guess) Enter a letter in word " + hidden
+ " > ");
// reading a word, converting to lower case, taking first
// character
char letter = scanner.next().toLowerCase().charAt(0);
// checking if this character is already made visible (exist on
// hidden)
if (hidden.contains("" + letter)) {
System.out.println("\t" + letter
+ " is already in the word");
}
// checking if this character is not in secret word
else if (!secretword.contains("" + letter)) {
System.out.println("\t" + letter + " is not in the word");
//using Jframw to create panel and show the image of hangman
every time when max attempts complete.
JFrame jjframe=new JFrame();
JLabel label=new JLabel(new ImageIcon("oops.png")); //oops.png is a
picture when user miss the character every time
//then the oops.png open every time . you can close the window or
you can continue with the guess word.
jjframe.setBounds(150,150,200,200); //setting the bounds of
jframe on the window screen
label.setBounds(10,10,100,100);//setting the bounds of label on the
Jframe screen
jjframe.add(label); // adding the label into jframe
jjframe.setVisible(true); //for showing the picture .
jjframe.setResizable(false);
misses++; // its a miss
} else {
// otherwise updating hidden word by calling replace method
hidden = replace(secretword, hidden, letter);
}
}
// displaying word and misses.
// using 'time' instead of 'times' if misses equals 1 (singular
// form)
if (misses == MAX_ATTEMPTS) {
JFrame jframe=new JFrame();
JLabel max=new JLabel(new ImageIcon("hangman.png")); //hangman.png
picture is showing when user attempts Max times .
//ImageIcon iii=new ImageIcon("oops.png");
jframe.setBounds(150,150,250,250);
max.setBounds(10,10,250,250);
jframe.add(max);
jframe.setVisible(true);
jframe.setResizable(false);
System.out
.println("Sorry! You could not guess the word. You missed "
+ MAX_ATTEMPTS
+ " attempts, the word was "
+ secretword);
} else if (misses == 1) {
System.out.println("The word is " + secretword
+ ". You missed " + misses + " time");
} else {
System.out.println("The word is " + secretword
+ ". You missed " + misses + " times");
}
// asking and reading user choice whether to continue or not
System.out
.print("Do you want to guess another word? Enter y or n> ");
ch = scanner.next();
}
}
}
and here is the sample output ---



here you can add image when user guess the right word .
i hope it would be helpful for you . Thank You !
hey dear i just need help with update my code i have the hangman program i...
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...
Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...
I have this program using class that plays the game hangman the only thing that I need to make is a file or a function that will store the 10 words ( hey, ace, cow, fix, fly, fun, ice, max, new, sam) when the user starts the game the words most be chosen randomly not in any order C++ code: // Header of the class #ifndef Hangman_H #define Hangman_H #include <string> #include <iostream> #include <string.h> using namespace std; class Hangman...
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...
I need help with my code when I run my code running the wrong thing like this After downSize() words.length=60003 wordCount=60003 vowelCount=206728 this is my code here import java.io.*; import java.util.*; public class Project02 { static final int INITIAL_CAPACITY = 10; public static void main (String[] args) throws Exception { // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) ...
I need help with my Java code. A user enters a sentence and the program will tell you what words were duplicated and how many times. If the same word is in the sentence twice, but one is capitalized, it will not count it as a duplicate. How can I make the program read the same word as the same word, even if one is capitalized and the other is not? For example, "the" and "The" should be counted as...
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...
Create a hangman program. Sample output from your program should look like the following: Current Status for userInputs= _ _ _ _ _ _ Enter next letter: a Current Status for userInputs=a _ _ _ _ _ _ Enter next letter: e Current Status for userInputs=ae _ _ _ _ e _ Enter next letter: i Current Status for userInputs=aei _ _ _ _ e _ Enter next letter: o Current Status for userInputs=aeio _ o _ _ e _...
I need help with this. I need to create the hangman game using char arrays. I've been provided with the three following classes to complete it. I have no idea where to start. HELP!! 1. /** * This class contains all of the logic of the hangman game. * Carefully review the comments to see where you must insert * code. * */ public class HangmanGame { private final Integer MAX_GUESSES = 8; private static HangmanLexicon lexicon = new HangmanLexicon();...
HEy GUYS PLZ I WROTE THIS CODE BUT I WAS ASKED TO ADD SOME
ASSERTION TESTS AND I HAVE NEVER DONE SUCH THING. CAN YOU GUYS
HELPS ME OUT ON HOW TO TEST A SIMPLE CODE SINCE ITS A GUESSING
GAME! THANK YOU. PYTHON
import random # here it allows us to use the benefits of the functions random #function 1 which is just a screen organized wordings def screen): screeninstructions () name input("Your Name : ") print('Welcome, name, 'This...