Need help with a wheel of fortune game
So, its sort of like hangman, All my code is able to do is to produce a random word, i have no idea how to change the letters in the string to this: "*", and how to change it back to the normal letters when the user guesses the write letter, please help.
Code :
String dictionaryWord= " ";
String[] words =
{
"hospital", "house", "car", "banana", "petres", "fly", "money", "computer"
}
;
String prompt = "enter a letter: ";
char letter;
letter = prompt.charAt(0);
Random r = new Random ();
dictionaryWord = words[r.nextInt(words.length)];
String [] inviwords = new String [dictionaryWord.length()];
for (int i = 0 ; i < dictionaryWord.length() ; i++)
{
c.setCursor (10, 10);
inviwords [i] = "*";
prompt += inviwords [i] + " ";
c.println (words [i]);
}
Re: Need help with a wheel of fortune game
Quote:
how to change the letters in the string to this: "*",
Quote:
how to change it back to the normal letters
Use the StringBuilder class to hold the letters of the word. You can index into the word and set the letters values.
Then create a String from the contents of the StringBuilder object.
Re: Need help with a wheel of fortune game
Thanks, but could you give me an example or maybe help me out a little more on how to turn all the characters in the string to this "*" i dont really understand
Re: Need help with a wheel of fortune game
Quote:
how to turn all the characters in the string to this "*"
You'd do it the other way. Start with a String of all *s and change them to the letters as they were guessed.
Several ways to get a Sting of *s. Take the length of the word and use it to substring from a long String like: "*****************************"
or use a loop to concatenate *s.