/**
* Write a description of class HangMan4 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class HangManSchool {
private static int nRetry = 6;
private static int index;
public static void main(String[] args) {
String pw;
String pws;
JPasswordField passField = new JPasswordField();
int Word = JOptionPane.showConfirmDialog(null, passField,
"Enter Your Word:", JOptionPane.OK_CANCEL_OPTION);
pw = new String(passField.getPassword());
JPasswordField passField2 = new JPasswordField();
int ReWord = JOptionPane.showConfirmDialog(null, passField2,
"Re-Enter Your Word:", JOptionPane.OK_CANCEL_OPTION);
pws = new String(passField2.getPassword());
if (ReWord == JOptionPane.OK_OPTION
&& pw.equals(new String(passField2.getPassword()))) {
String out = "Congratulations, Let The Games Begin!";
JOptionPane.showMessageDialog(null, out);
}
else if (pw != pws) {
String out = "The Word Was Re-Entered Wrong, Please Try Again.";
JOptionPane.showMessageDialog(null, out);
System.exit(0);
}
if (pw == pws && Word == ReWord)
System.out.println("Congratulations, Let The Games Begin!");
if (ReWord == JOptionPane.CANCEL_OPTION
|| ReWord == JOptionPane.CLOSED_OPTION) {
String out = "Thanks For Using HangMan V.05!";
JOptionPane.showMessageDialog(null, out);
}
int length = pw.length();
char[] letters = new char[length];
String word = pw.toLowerCase();
int o = 0;
while (length > 0) {
System.out.print("_ ");
length--;
}
System.out.println("\nThe Game Has Now Begun");
while (nRetry != 0) {
System.out.println("\nPlease enter a letter (A-Z)");
String guesses = kb.nextLine();
String guessLetter = guesses.toLowerCase();
if (guessLetter.length() > 1) {
String out = "ERROR MESSAGE!: Please Enter Only One Letter For Each Guess!";
JOptionPane.showMessageDialog(null, out);
}
System.out.println("The letter that you have guessed is: " + guessLetter);
if (word.contains(guessLetter)) {
System.out.println("Good job, you guessed the letter in the word!");
index = pw.indexOf(guessLetter);
letters[index] = guessLetter.charAt(o);
/**
* Prints the matched letter to the screen
*/
private static void printMatchedWord(String word, char[] letters, String guessLetter, int index, String pw) {
for (int i = 0; i < letters.length; i++) {
System.out.print("-");
}
}
/**
* @param word - The word the player needs to guess
* @param letters - Character array of matched letters
*/
private static void isMatching(String word, char[] letters) {
String enteredWord = new String(letters);
if (enteredWord.equals(word)) {
String out = "Congratulations, You Won!";
JOptionPane.showMessageDialog(null, out);
System.exit(0);
}
}
}
all i need is a loop that makes a word with two or more of the same letter word. like if you type in pokemon it wont recognize the second o and will loop on forever until you die.
and how do you make it look like real code on the website with the indents ad stuff. thanks guys.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
1
> how do you make it look like real code on the website with the indents ad stuff
click the 'edit' button beside your post
highlight/select all of your posted code
click the 'code' button (above the typing area)
click preview to make sure its OK
click 'submit' (?)