Hi,
I have a Uni assignment which requires me to make a Hangman program without using arrays.
I have done this so far:
//class Hangman
public class hangman
{
private int maxTries=10; //variable to coutn amount of letter guessess
private int wordLength;
//Retrieves word from words.txt file
Scanner fileScan =new Scanner(new FileInputStream("words.txt"));
String secretWord = fileScan.next();
//Creates a StrungBuffer for viewing the letters to be guessed
StringBuffer wordLength =new StringBuffer();
for(int i=0; i= <= secretWord.length(); i++)
word.append("_");
System.out.println(wordLength);
//Creates a StringBuffer to display the guessed letters
StringBuffer guessedLetters =new StringBuffer();
System.out.print("Enter a character?");
Scanner inScan = new Scanner(System.in);
letter = inScan.next();
guessedLetters.append(letter + " ");
while(maxTries > 0)
{
System.out.println("The letters that you have guessed are: " + guessedLetters);
if(secretWord.indexOf(letter) != (-1))
{
secretWord.indexOf(letter);
System.out.println("correct");
}
else
maxTries--;
System.out.println("You have " + maxTries + "guesses to go.");
}
But i'm struggling to display the guessed letters in terms of "_a__v____er" format. If anyone knows an easy way to do this or can post an old hangman assignment you've done i'd greatly appreciate it.
Thanks in advance