Results 1 to 5 of 5
Thread: Hangman Game..
- 05-07-2009, 04:29 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
Hangman Game..
Ok so i'm super struggling in writing a hangman game in blueJ. So far i have a class for canvas, a class to control the canvas, a class to generate random words, and the main class. Now the generating works fine, but i'm just so burned out where im at right now.. Please bare with me as i am super NEWB. Right now i am at the point where the person types a letter and then i search thru the word. I'm not sure how to handle when the word has the same letter in it twice, and im also not sure how to handle it when it is incorrect because when i compile and i type a letter if it is incorrect incorrect shows up the screen like 8 times, dont get why. i need some help someone!!! lol
Java Code:import java.util.*; /** * hangman * * @author petey * @version (a version number or a date) */ public class Hangman { // instance variables - replace the example below with your own private Scanner InputS; private int MissedTimes; private Generator generator; /** * Constructor for objects of class Hangman */ public Hangman() { // initialise instance variables InputS = new Scanner(System.in); generator = new Generator(); MissedTimes = 0; } public String word() { String word = generator.generate(); return word; } public void startGame() { boolean yesno=false; System.out.print("Play HangMan?(Yes/No)"); String toDo = InputS.nextLine(); toDo = toDo.toLowerCase(); if (toDo.equalsIgnoreCase("yes")) { yesno=true; } else { yesno=false; } while(yesno) { String secretWord = generator.generate(); while (MissedTimes < 8 ) { System.out.print("Please type a letter"); System.out.print(" "); String Letter = InputS.nextLine(); char letterChar = Letter.charAt(0); for (int i = 0; i < secretWord.length (); i++) { if(secretWord.charAt(i) == letterChar) { // found System.out.print(" "); System.out.print("Correct! "+ letterChar + ""); System.out.print(" "); // draw the letter on the canvas } else { System.out.print("Incorrect"); } } } System.out.print("Play HangMan?(Yes/No)"); InputS = new Scanner(System.in); toDo = InputS.nextLine(); toDo = toDo.toLowerCase(); if (toDo.equalsIgnoreCase("yes")) { yesno=true; } else { yesno=false; System.out.print("Goodbye."); } } } }
- 05-07-2009, 05:15 AM #2
Incorrect (and Correct) will be repeated for every letter, as it is inside the for loop. Put the checks inside the loop, but the messages outside it.
Also, what is the point of this?
Java Code:System.out.print(" ");Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 05-07-2009, 06:39 AM #3
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
- 05-07-2009, 08:48 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 52
- Rep Power
- 0
if you want to print space you can use \t option
- 05-07-2009, 02:24 PM #5
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
Similar Threads
-
Need help with hangman game
By kurt in forum New To JavaReplies: 4Last Post: 04-25-2009, 06:47 PM -
Need help with Hangman!!!
By chinasome in forum New To JavaReplies: 10Last Post: 11-09-2008, 04:42 AM -
Hangman Help!!!
By chinasome in forum New To JavaReplies: 5Last Post: 11-08-2008, 02:30 AM -
Hangman Game
By L23 in forum New To JavaReplies: 8Last Post: 07-03-2008, 01:56 PM -
Create the game Hangman
By barney in forum New To JavaReplies: 1Last Post: 08-06-2007, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks