Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help with a wheel of fortune game

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.
    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]);
     
            }
    Last edited by DanTheSand; January 14th, 2012 at 12:31 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help with a wheel of fortune game

    how to change the letters in the string to this: "*",
    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.

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help with a wheel of fortune game

    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.

Similar Threads

  1. Simple game that requires me to load game settings from a file
    By 14fenix in forum Java Theory & Questions
    Replies: 5
    Last Post: December 1st, 2011, 09:21 PM
  2. TIC-TAC-TOE GAME
    By umerahmad in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 29th, 2011, 12:15 PM
  3. Need Help with Game
    By Shivam24 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 18th, 2011, 03:58 PM
  4. Help me with My Game.
    By jtvd78 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 13th, 2011, 04:14 PM
  5. Game 3x3
    By Koren3 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 08:43 PM