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...
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 not use any capital letters): ");
String word = input.next();
String []Player1Word = new String[word.length()];
for(int a = 0; a < word.length(); a++)
Player1Word[a] = word.substring(a,a+1);
String []Player2Guess = new String[word.length()];
System.out.println("Player 2 - The word you are trying to guess has " + word.length() + " letters in it.");
for (int k = 0; k < word.length(); k++)
{
System.out.print("__" + " ");
if(k == word.length() - 1)
System.out.println(" ");
}
while(correct<word.length() || wrong<=6)
{
System.out.print("Player 2- please guess a letter: ");
String guess = input.next();
Player2Guess[guesses] = guess;
for(int g = 0; g < word.length(); g++)
{
if(Player2Guess[guesses] = Player1Word[g])
correct++;
int k = Player1Word.indexOf(guess);
System.out.println("there is a "+guess);
for (int b = 0; b < word.length(); b++)
{
if(b==k)
System.out.print(guess+" ");
System.out.print("__" + " ");
if(b == word.length() - 1)
System.out.println(" ");
}
else if
wrong++;
}
guesses++;
}
}
}