473,765 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with hangman program

3 New Member
Hi! I was wondering if someone could please help me with a hangman program that I have to do. I have some ideas, but really don't know what to do or where to start. My program needs to be: interactive with the user, menu based(like Menu: 1. Play hangman 2. Exit program), have a dictionaryand use a random method(create arrays of Strings or ListArray of Strings. e.g. : String [] dictionary =
“apple”, “ball”, “cat”, “dog”, …..} minimum words requirement is 200.), more than one method, and one method has to return a value. The final status of the game-8 failed attempts is a loss, each wrong answer should print this:(00)-<=< (hangman), notify the user of the loss and print the correct word, if the user guesses correctly the message should be “ You guessed it right,” and display the Menu again.

Here are my thoughts-
I think I should do a do/while loop like this:

int n;
boolean done = false;
do
{
Scanner scan = new Scanner(System. in);
System.out.prin t("Enter your selection:\n 1. Play Hangman \n 2.Exit
program");
n = scan.nextInt();

if(n == 1)
{
//hangman program goes here and dictionary (dictionary[rand()%200])
}

if( n==2)
{
done = true;
}

}
while(! done);

System.out.prin t("GAME OVER");

Here are the 200 words I want to use:
"boy", "girl", "mother", "father", "sister", "love", "sky", "wind", "water", "study", "ball",
"cat", "dog", "puppy", "kitten", "apple", "pear", "lemon", "mango", "peach", "apricot", "chips", "steak", "fries", "cheese",
"patatoe", "wedge", "heel", "hand", "foot", "arm", "leg", "nose", "face", "mouth", "tongue", "fingers", "toes", "line", "space",
"phone", "cord", "core", "grass", "trees", "birds", "animals", "lazy", "funny", "king", "queen", "heart", "heat", "cold", "sun",
"moon", "movie", "theater", "hairy", "big", "small", "large", "huge", "pig", "donkey", "cow", "chicken", "pizza", "bread", "stones",
"sticks", "leaves", "letters", "alphabet", "soup", "hungry", "tired", "sleepy", "noisy", "caring", "friends", "month", "day", "light",
"toothbrush ", "savings", "bank", "account", "teller", "paper", "pencil", "tea", "coffee", "spirit", "ghost", "can", "melon", "necklace",
"screen", "baloon", "string", "calendar", "work", "toys", "kids", "school", "class", "campus", "freedom", "liberty", "happiness" ,
"university ", "message", "marker", "crayon", "eraser", "music", "lyrics", "songs", "ballads", "shapes", "triangle", "circle", "rectangle" ,
"square", "oval", "show", "video", "player", "team", "sport", "basketball ", "football", "soccer", "softball", "baseball", "tennis",
"hockey", "lacrosse", "volleyball ", "circut", "blade", "scratch", "hit", "home", "house", "safe", "safety", "number", "count", "bear",
"goose", "llama", "panda", "lion", "tiger", "cheetah", "computer", "crackers", "rice", "fan", "shoes", "book", "story", "princess",
"prince", "jester", "court", "jury", "judge", "bench", "scandal", "name", "newspaper" , "press", "shove", "tear", "cry", "magic", "tricks",
"cereal", "breakfast" , "lunch", "dinner", "main", "course", "fork", "spoon", "knife", "lamp", "desk", "bottle", "highlighte r", "cap",
"medicine", "six", "seven", "flower", "rose", "petal"

I know my hangman program should start something like this, but I don't know where to go from here:
public Hangman()
{
misses = 0;
wordIndex = 0;
lettersUsed = new boolean[Character.MAX_V ALUE];
}

private void clear()
{
int k;
for(k=0; k < Character.MAX_V ALUE; k++) {
lettersUsed[k] = false;
}

Can someone please help me?

Thanks!
Jul 20 '07 #1
4 2598
JosAH
11,448 Recognized Expert MVP
There's another user who hangs around here: Nomad; this user is also interested
in implementing this Hangman game; send him a private message (PM, see
the top right part of your browser window) and see if he's still interested.

If both of you get stuck, feel free to come back here and ask away. First hint:
have a look at the Pattern and Matcher classes.

kind regards,

Jos

ps. and welcome to TSDN.
Jul 20 '07 #2
r035198x
13,262 MVP
And if you really want to make this one good (different categories e.t.c) , you might want to consider storing the words in a text file. Then the curent tip of the week might become relevant in some areas on this one as well.
Jul 21 '07 #3
princessfrost
3 New Member
Ok, so this is what I have so far and I want to use the private boolean contain method to:
1. letters guessed(like add a brand new letter thats wrong or right)
2. the guessed letter (the wrong letter)
3. if they guessed the letter before a statement that says "you guessed this already, please try again"
4. if they enter an invaild answer(like a number)

can someone please help me to do this?
(first file)

import java.io.Buffere dReader;
import java.io.FileRea der;
import java.io.IOExcep tion;
import java.util.*;


public class HangManGame7
{

static String [] dictionary = new String[200];



static String word = "";
static ArrayList guesses = new ArrayList();
static ArrayList wrongLetters = new ArrayList();
static int numberOfTrys = 0;
static String[] deadMan = {"(","0","0",") ","-","<","="," <"};

public HangManGame7(){
try {
BufferedReader in = new BufferedReader( new FileReader("dic tionary.txt"));
int i = 0;
while (i < 200) {
dictionary[i++] = in.readLine();
}
in.close();
} catch (IOException e) {
System.err.prin tln("Error: File failed to close");
}
}

public void play() {
System.out.prin t("Let's play HANGMAN!\n");
System.out.prin tln("Instructio ns: Enter a letter when asked. " +
"Try to guess the word in less than 8 tries to stop from being hanged! Good luck!\n\n");
word = dictionary[(int) (Math.random()% 200)] ;
buildWord();
System.out.prin tln("Word "+guesses);
System.out.prin tln("Wrong letters "+wrongLetters) ;
System.out.prin tln("Status ");
for (int i = 0; i < numberOfTrys; i++){
System.out.prin tln(deadMan[i]);
}

}

private static void buildWord(){
for (int i = 0 ; i < word.length(); i++){
guesses.add("_ ");
}
}

private static void printArray(Arra yList array){
for (int i = 0; i < array.size(); i++){
System.out.prin tln (array.get(i));
}
}


}




(second file )
import java.io.FileNot FoundException;
import java.util.Scann er;


public class Main2
{
public static void main(String[] args) throws FileNotFoundExc eption
{
int choice;
boolean done = false;
do
{
Scanner scan = new Scanner(System. in);
System.out.prin t("Enter your selection:\n 1. Play Hangman \n 2. Exit program\n\n");
choice = scan.nextInt();

if(choice == 1)
{
HangManGame7 hmg = new HangManGame7();
hmg.play();

}
else if(choice == 2)
{
done = true;
}

}
while(!done);
System.out.prin t("GAME OVER");
}
}


and the dictionary.txt file i have
boy
girl
mother
father
sister
love
sky
wind
water
study
ball
cat
dog
puppy
kitten
apple
pear
lemon
mango
peach
apricot
chips
steak
fries
cheese
potatoes
wedge
heel
hand
foot
arm
leg
nose
face
mouth
tongue
fingers
toes
line
space
phone
cord
core
grass
trees
birds
animals
lazy
funny
king
queen
heart
heat
cold
sun
moon
movie
theater
hairy
big
small
large
huge
pig
donkey
cow
chicken
pizza
bread
stones
sticks
leaves
letters
alphabet
soup
hungry
tired
sleepy
noisy
caring
friends
month
day
light
toothbrush
savings
bank
account
teller
paper
pencil
tea
coffee
spirit
ghost
can
melon
necklace
screen
balloon
string
calendar
work
toys
kids
school
class
campus
freedom
liberty
happiness
university
message
marker
crayon
eraser
music
lyrics
songs
ballads
shapes
triangle
circle
rectangle
square
oval
show
video
player
team
sport
basketball
football
soccer
softball
baseball
tennis
hockey
lacrosse
volleyball
circuit
blade
scratch
hit
home
house
safe
safety
number
count
bear
goose
llama
panda
lion
tiger
cheetah
computer
crackers
rice
fan
shoes
book
story
princess
prince
jester
court
jury
judge
bench
scandal
name
newspaper
press
shove
tear
cry
magic
tricks
cereal
breakfast
lunch
dinner
main
course
fork
spoon
knife
lamp
desk
bottle
highlighter
cap
medicine
six
seven
flower
rose
petal
Jul 22 '07 #4
r035198x
13,262 MVP
1.) Please don't post all your code and text all the time.
2.) When you have to post code, let it be small snippets of the parts that you need help with.
3.) Have you written down your specs, and design first?

P.S Did you manage to talk to nomad?
Jul 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
15802
by: tigrfire | last post by:
So I'm trying to write a hangman game and the output is coming out a little strange. Here's my code thus far: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> int hangman()
2
1602
nomad
by: nomad | last post by:
Hello everyone. I'm trying to write a ramdom word program using a arraylist. here is the code so far. class WordClass1 {// there is another PersonClass1 project. private String wd_id; private String word_name;
47
11463
by: araujo2nd | last post by:
Originally Posted by araujo2nd my name is andre, im from south africa, i was wondering if any1 could help me with a hangman application, im now in grade 11 and have a huge portfolio piece to do by the 15th which i have just started now, i have always struggled with java and would rele appreciate all the help that i can get. Pls could some1 help me as much as u can, im nt asking u to do the program for me but if u could pls take me steps through...
3
2952
by: kaka_hunter | last post by:
#include <iostream> #include <fstream> using namespace std; const int max_tries=7; int earnings=0; int wordnum; void getword () { ifstream fin;
5
4190
by: av3rage | last post by:
I have never done any programming in my life but I have decided to go into engineering and in doing so we have to take this intro to programming course and I am pretty clueless. I am starting to get the hang of how python works but to put my thoughts into the program to make it run is the confusing part for me. The task is to implement a Hangman game and the Program Specifications are: 1) Output a brief description of the game of hangman...
8
3745
by: tidiz | last post by:
Hi, I'm trying to make a hangman game that should look like this: Welcome to Hangman ______ Your guess: c Success! __cc__ Your guess: b
25
3959
by: yottabyte | last post by:
Hey, I just started programming this September and I have an assignment in which I am supposed to create a hangman game. This is my first post on this forum so forgive me for any "noob" mistakes Now I'm still learning Java so this will be a basic program running in the console window (no GUI) using strings loops, arrays, etc but hopefully nothing too complicated. I've developed somewhat of an algorithm for the program, but it's really simple so...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.