Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for C! It uses a words file, on the bottom of this post you will see a small example of a few words. You can adjust the default words file in the getWord() function (line 164). If the file does not exist, the script will ask for another words file. The words need to be separated by a |. Words files can be found can be found [URL="http://www.hangman.symbolwebdesign.nl/wordsfiles.php"]here[/URL]. ~G words.txt [CODE]abbey|abruptly|affix|askew|axiom|azure|bagpipes|bandwagon|banjo|bayou|bikini|blitz|bookworm|boxcar|boxful|buckaroo|buffalo|buffoon|cobweb|croquet|daiquiri|disavow|duplex|dwarves|equip|exodus[/CODE]

Member Avatar
Member Avatar
+0 forum 3

hi.i am new to c++.i need to make hangman game for university project.could some on tell me what is the problem with this part of the code?thanks in advance #include <iostream> #include <iomanip> #include <cstdlib> #include <ctime> #include <string> #include <windows.h> using namespace std; int main() { //variable declaration string secret_word; //randomly print a name of a country from list enum Country {PAKISTAN=1,OMAN,IRAN,EGYPT,PHILLIPINES}; //possible names of countries srand(time(0)); int Country=1+rand()%5; { if (Country==1) { secret_word="PAKISTAN"; } if (Country==2) { secret_word="OMAN"; } if (Country==3) { secret_word="IRAN"; } if (Country==4) { secret_word="EGYPT"; } if (Country==5) { secret_word="PHILLIPINES"; } } char data[50]; int …

Member Avatar
Member Avatar
+0 forum 1

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for Java! It uses a words file, on the bottom of this post you will see a small example of a few words. The source code for other languages can be found here on DaniWeb and on my new website: [URL="http://www.hangman.symbolwebdesign.nl/"]http://www.hangman.symbolwebdesign.nl/[/URL]. Due to the fact it is not possible (in web apllications) to open a words file using Java, it is required to directly put the words string separated by a | into the string …

Member Avatar
Member Avatar
+2 forum 16

Hi, I have a quick question. I am making a hang man game for project (I am at university as a computer science major), I have completed most of the game but have run into one small issue which has been given me a big problem. Right now I am using an ArrayList in conjunction with nested loops and methods to get the game done. Again the game is finished, there us just one issue which I am having. One of the requirments is that when the user inputs a letter, and the letter that is guessed mathches a letter(s) …

Member Avatar
Member Avatar
+0 forum 1

I have to complete this programming homework which consists of building a hangman game. However, the problem is: I do not know how to make it so that, when you guess a correct letter, it reveals that letter in the hidden word while still keeping the other parts of the word hidden. For example : The hidden word is REVEAL. You guess "E". It should now show ".E.E.." in the user's screen. If you guys could help me out with this, I'd be extremely grateful, especially since I'm in a big hurry! By the way, since I live in Quebec, …

Member Avatar
Member Avatar
+0 forum 6

**I need urgent help with a hangman game it needs to be really basic so i can understand but it needs to include an array and an onscreen keyboard please please please help!

Member Avatar
Member Avatar
+0 forum 1

I am a beginner in java does not know much about it. But to practise it I have tried to simulate the popular game Hangman using simple methods.Please Guide me with the code In this program the words are given by the user and then they are converted in to dashes. Its like 2 player game 1st player enters the word or sentence and then seconds player tries to guess it. but in this program the words entered by first player is displayed.How can I hide that words after the first player had finished Entering the words. Also please help …

Member Avatar
Member Avatar
+0 forum 3

Hey guys, I'm making a hangman project just for fun, and i was wondering if you could help me. * I have 5 classes * class 1- main (basically controlls everything except recognizing where the letters are located in the word and printing the hangman picture) * class 2- char_array (sees if the letter is in the word multiple times, and prints the letters the operator has figured out (ex: bumb-e) ) * class 3 - graphics (just full of methods that print the hangman on the screen depending on how many letters you have gotten wrong) * class 4 …

Member Avatar
Member Avatar
+0 forum 9

import java.util.Scanner; import java.util.Random; public class HangmanGame2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); final String[] WordList = { "porcupine", "flamingo", "sasquatch", "poseidon", "minnie mouse", "mickey mouse", "galileo" }; String ChosenWord = WordList[(int)Math.random()*WordList.length]; StringBuffer display = new StringBuffer(ChosenWord.length()); for (int i = 0; i < ChosenWord.length(); i++) display.append("*"); int NumberOfTries = 0; System.out.print("Let's Begin \n\n"); System.out.println("Instructions: Enter a letter when asked. Try to guess the word in less than 6 tries or you will be a Dead Man! Good luck!\n\n"); boolean correct = false; while (NumberOfTries < 6 && !correct) { String UserGuess = input.next(); …

Member Avatar
Member Avatar
+0 forum 1

[import java.util.Scanner; import java.util.Random; public class HangmanMy { public static void main (String[] args){ System.out.println("Welcome to the game Hangman :)/>"); Scanner input = new Scanner(System.in); boolean done = false; String guess; String guesses = ""; char letter; int wrongGuess = 0; StringBuffer dashes; System.out.println("Choose a category -> places / games / animals / subjects "); String words = WordsToChoose(input.nextLine()); dashes = makeDashes(words); while (! done) { System.out.println("Here is your word: " + dashes); System.out.println("Guesses so far: " + guesses); System.out.print("enter a guess (letter or word): "); guess = input.next().replaceAll("\\W", ""); // process the guess if (guess.length() > 1) { if …

Member Avatar
Member Avatar
+0 forum 2

I am fairly new to Pascal and I have been attempting to write a hangman game. I am aware that there are probably so many better ways to do this than I have done but I am having some problems where the exit variable is not met because the current variable has a 1 appended to it. As far as I can tell I have not initialised it with a 1 nor can I find anywhere that would append this 1. It is incredibly frustrating and I am completely stumped. Any help would be greatly appreciated. Program Hangman; Procedure Play; …

Member Avatar
Member Avatar
+0 forum 1

I'm new at this. But I'm taking a class and I need to turn this in by Friday. Please help me. I can only use strings and arrays. My hangman program needs five things: 1. user is prompted for a word that is ten letters or less, or else the program rejects it and asks for reentry. 2. if the word is too long or has a nonletter, the program rejects it and asks for reentry. 3. If the word has uppercase letters, it needs to be converted to lowercase 4. if there is more than 6 wrong guesses, the …

Member Avatar
Member Avatar
+0 forum 4

I need help with my java code for the game hangman... we are using eclipse to write the game and using three main files to start...hangman.java hangmanlexicon.java and hangmancanvas.java. the first part of the assignment, is to create a ConsoleProgram for the game and this is what i have so far. /* * File: Hangman.java * ------------------ * This program will eventually play the Hangman game from * Assignment #4. */ import acm.graphics.*; import acm.program.*; import acm.util.*; import java.lang.*; import java.awt.*; public class Hangman extends ConsoleProgram { /* * Constants */ public static final int N_TRYS = 13; public static …

Member Avatar
Member Avatar
+0 forum 7

This is a simple hangman game that I wrote using my beginner python skills. Though this game is playable, there must be lots of things I must've been doing wrong or the methods I'm using here may be not so pythonic. So I want some suggestions on how to improve this game. The 'wordsdict.pkl' file contains a pickled dict with words as keys and meanings as their values. e.g. {'word': 'its meaning'}

Member Avatar
Member Avatar
+1 forum 4

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for JavaScript! It uses a words file, on the bottom of this post you will see a small example of a few words. The source code for other languages can be found here on DaniWeb and on my new website: [URL snippedL]. You can adjust the words file in the initGame() function (line 81). The words need to be separated by a |. Words files can be found can be found [URL="http://www.hangman.symbolwebdesign.nl/wordsfiles.php"]here[/URL]. By default, the …

Member Avatar
Member Avatar
-1 forum 3

So i wanted to write a Hangman game and i started it, as im newbie programmer it took me several days to track all the bugs etc. Meanwhile i want to get good habits on designing and i read that Getters and Setters arent the best way to go for a class design. I tryed my best to lead this project to a good design but i need a feedback to see if im on the right track, please, comment on everything you see that are lame or that can be build better. Im scared of comments like "looks good, …

Member Avatar
Member Avatar
+0 forum 10

I am not totaly sure my code for my revealLetter is correct....I can't quite convert letter string into an char array so i just left it as hiddenWord == letter in the code.... package program.p02; public class WordHider { private String hiddenWord; private String partiallyFoundWord; private int NUMBER_MISSES = 5; public int revealLetter(String letter) { //reveals letter stored in the parameterized string. int numOfTimesLetterAppears = 0; for (int i = 0; i < hiddenWord.length(); i++) { //compare letter of hiddenWord at i with letter //String s = new String(hiddenWord.charAt(i)); if (hiddenWord == letter){ //partiallyFoundWord[i] = letter; // changes astrix to …

Member Avatar
Member Avatar
+0 forum 3

package program.p02; import java.io.*; import java.util.*; import java.lang.*; public class Dictionary { private String[] dictionary; private static final int NUMBER_OF_WORDS = 81452; private static String FILE_NAME = "dictionarycleaned.txt"; //no arg constructor??? public Dictionary() { Scanner fin = null; //open and test the stream try { fin = new Scanner(new File(FILE_NAME)); }//end try catch (FileNotFoundException e) { System.err.println(e); System.exit(1); }//end catch fin.close(); } public String getRandomWord() { //class random?? random number generator Random generator = new Random(81452); int r = generator.nextInt(); return dictionary[r]; }//end getRandomWord() }//end dictionary class I am having a bit of trouble with my file IO it is …

Member Avatar
Member Avatar
+0 forum 3

I have my project due of hangman and it is worrying me lately. I need to make a hangman game. I have studied arrays, functions, loops, if else statements. That is about it. I haven't done 2d arrays. Will do it now, because someone told me it is not possible to make a hangman game of 40 words without 2d arrays. My question to you is. *how to store words for hangman? Say I saved them in arrays. But then how do i retrieve them? *How to I randomly generate words for hangman? *I know how to randomly generate numbers, …

Member Avatar
Member Avatar
+0 forum 2

I am using: underscoredWord = Regex.Replace(word, "[^" + correctLetters + "]", " _"); for my Hangman game. It basically chops the word up and replaces all the text with an underscore. This works fine if the guessing word is only "one word". So the word: "Building" will get converted to: _ _ _ _ _ _ _ _ How do I improve the above Regex express so that it puts underscores for all letters and a forward slash "/" for spaces? So the words: Hello Batman Be turned in to: _ _ _ _ _/_ _ _ _ _ _ …

Member Avatar
Member Avatar
+0 forum 5

OK, i'm working on a hangman game in cmd prompt. I'm about halfway done, but i have hit a wall regarding the secret word, and the user guess. Now mind you, my professor has not taught the class any array manipulation methods or techniques for finding specific char in an array of strings. My problem arises when the secret word is chosen randomly by the computer, I do not know how to "cover" the secret word in asterisks or whatever char. I imagine an algorithm where i use array.length and match the user input char to individual chars in the …

Member Avatar
Member Avatar
+0 forum 8

Hello, I joined about 5 minutes back. I need to complete my computer project, which is a hangman game in c++, by today. Based on what my teacher taught me, I have created a code that runs like this- [CODE]#include<iostream.h>//These are the only header files taught. #include<conio.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int display(char [], int&); int input(char [], char&, int&, int); int l; void main() { clrscr(); int n,res,pos=0,state=0; char num[50],ch, M [][50]={ "Roman Holiday","Breakfast At Tiffany's", "Sweet November", "Only You","Love, Actually"}; randomize(); n=random(5); puts(M[n]); char s1[50]; strcpy(s1,M[n]); display(s1,pos); cout<<"\n \nYou have "<<pos<<" blanks to fill.Good luck."<<endl; input(s1,ch,state,pos); cout<<state; getch(); } …

Member Avatar
Member Avatar
+0 forum 14

Hey everyone! I am trying to writing a program that will play hangman. I have an understanding, on paper, of how to write the program... but I just cant fully convert it into java. I have started the program but I've gotten to a point where I'm stumped. Any help will be much appreciated! here is what i have so far... [CODE]import java.util.Scanner; class HangMan { public static void main (String args[]) { Scanner input = new Scanner(System.in); int correct = 0; int guesses = 0; int wrong = 0; System.out.print("Player 1 - Input the word to be guessed (do …

Member Avatar
Member Avatar
+0 forum 7

i want some help i have this progamm and i want to add points when a letter is found 10 points PLZ HELP ME! i also want to make it for two players Module Module1 Public zoes As Byte Sub Main () Dim un As String un = Console.ReadLine() Dim word As String = un Dim word As String 'Initialize the secret word Computer Dim display As String = MakeDisplay (word) Dim letter As String If word <> "end" Or word <> "End" Then Console.Write ("Please enter keyword") word = Console.ReadLine () End If zoes = Len (word) - 2 …

Member Avatar
Member Avatar
+0 forum 2

I am having trouble completing This hangman project. It mmost be done using model view controller pattern. Here is what i have so far //Header file declarations import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileInputStream; import java.io.IOException; import java.util.Scanner; //Class declaration class HangmanModel extends JFrame implements ActionListener { public int attempts = 13; private JTextField _tfWordIO = new JTextField(); private JTextField _tfGuessChar = new JTextField(); private JButton _resetBtn = new JButton("Restart"); private JLabel _lblResponse = new JLabel(); public int errors; int wordlength; boolean solved; String secret; //read in secret string //String displaySecret; //generate as many "*"s as secret …

Member Avatar
Member Avatar
+0 forum 17

The error is: class, interface, or enum expected. I've never seen or heard of this error before surprisingly, and I've written all of my code the same way, so I'm not too sure what's wrong with. I've put red arrows around the lines in question. Thanks in advance! [CODE]/* Hangman :) */ import java.util.Scanner; class Hangman { public static void main(String[] args) { Scanner guess = new Scanner(System.in); System.out.println("Hello, and welcome to Hangman!"); System.out.println("Difficulty(1-3): "); int diff = guess.nextInt(); if(diff==1) { Play obj = new Play(); obj.Start(diff); }else{ if(diff==2) { Play obj = new Play(); obj.Start(diff); }else{ Play obj = …

Member Avatar
Member Avatar
+0 forum 2

What my problem is I don't know how do I set it up so that when the entire word has been guessed I can stop the game and tell the user they won or lost. I tried adding in another if statement after maxTries--; where it says if (maxTries == 0) { println("You lose.") but the message doesn't show up. Other problem is that the letters being guessed are not being recorded properly, I thought it was fine but after testing it a few times the letters I've guessed would disappear from the display making the user retype them. And …

Member Avatar
Member Avatar
+0 forum 4

So I've made a game called HangMan, but it still needs the finishing touches. Anyways, a bit about the game... A JFrame shows 26 buttons for the letters of the alphabet and a whole set of other buttons to make up empty slots (they eventually will be filled in everytime the user picks the correct letter.) Now, the finishing touches are.. I need to implement methods hasWon() and gameOver(). I've wrote them up, but their messages like "YOU WON!!" and "GAME OVER!!" do not show up. Can anyone help me try to call these messages to set the JLabel error? …

Member Avatar
Member Avatar
+0 forum 9

I have a Computer Science project due Monday. We have to make a game and use GUI in order to ensure ourselves a good score. I decided to make Hang Man. The class reads in a txt file of common SAT words (I'm a sophomore in high school, so I need to start studying these words). Some background on my progress: I've had to make several new files for my classes because my old ones got all corrupt and messed up. Like whenever I wanted to add changes after running a successful program, the class wouldn't read any of my …

Member Avatar
Member Avatar
+0 forum 11

Hey everybody, Lately I have written the game Hangman in many different languages (C, JavaScript, Java and PHP so far). Here is the code snippet for PHP! It uses a words file, on the bottom of this post you will see a small example of a few words. The source code for other languages can be found here on DaniWeb and on my new website: [URL snipped]. You can adjust the words file in the getWord() function (line 21). The words need to be separated by a |. Words files can be found can be found [URL="http://www.hangman.symbolwebdesign.nl/wordsfiles.php"]here[/URL]. By default, the …

Member Avatar
Member Avatar
+0 forum 3

The End.