Hi all, I am taking a very beginner java class at my high school, and am completely stuck on a program we are working on. It is essentially a very simple hangman game, in which the user enters a 5 letter word, then enters guesses. I will post the directions as well as what i have.
Thanks,
Perry
Write a hangman game. Your game should:
* Ask the user for a 5 letter lower case word. Error check the
* length of the word to make sure it's 5 letters long. You
* may assume all of the letters are lower case.
* Print out guess (it should start as 5 underlines) and ask the
* user for a lower case letter. This should all be in ONE
* JOP window.
* Check to see if the letter is in the word and update the guess
* if it is. You do not need to show this in a JOP window.
* Continue displaying the guess and asking for letters until
* the user has guessed the word.
* Print a congratulations message that contains the word and
* the number of letters the user had to enter.
*
* Use the main method below. DO NOT change it. You can
* comment out method calls until you write them.
*
* Things you could add:
* Have it work for any sized word.
* Have it work for upper & lower case letters.
* Show the incorrect letters the user has chosen.
----------------------code(Java)
---------------------------------public class Hangman { public static void changeJOP() { UIManager.put("Label.font", new FontUIResource (new Font("Nyala", Font.BOLD, 28))); UIManager.put("OptionPane.messageForeground",Color.white); UIManager.put("Panel.background",new Color (0,0,205)); UIManager.put("OptionPane.background",Color.white); UIManager.put("Button.background",Color.white); UIManager.put("Button.foreground", new Color(25,25,112)); UIManager.put("Button.font", new FontUIResource (new Font("Nyala", Font.BOLD, 14))); } public static String enterWord(String word) { int num; String s; do{ s = (JOptionPane.showInputDialog("Enter a 5 letter word:")); num= s.length(); }while(num != 5); return s; } public static void enterLetter(char letter, String word) { } public static void checkLetter() { } public static void main(String[] args) { changeJOP(); String word="", guess=" "; char letter; int count = 0; word= enterWord(); while(!guess.equals(word)) { letter = enterLetter(guess); count++; guess=checkWord(word, guess, letter); } printCongrats(word, count); } }
The main was built for us, everything else i did.
I have been looking at it all day, and cannot come up with anything to do next.
Thanks all for your time..


LinkBack URL
About LinkBacks
Reply With Quote
The idea is you put [code] at the start of a section of code and [/code] at the end. That way the forum software displays it with indentation intact. The same applies to error messages and things where indentation is necessary for readability - there seems to be no "pre" markup, so we use [code]...[/code] there too. It doesn't matter with this code, but you might find using *spaces* rather than tabs to indent is a good idea. Tabs can be a bit unpredictable at the best of times, and many browsers render them uncomfortably wide.