Help with a word guessing game.
I have a problem with one of my projects I'm working on. It's kind of like wheel of fortune. It's a basic 2 player game. One player submits a word or words. Then the other player guesses either a character or the whole word. I'll post what code I have so far and at the end describe my problems.
Code:
import java.util.*;
import java.io.*;
public class wof // wof stands for wheel of fortune
{
public static final long TIME_LIMIT = 10000L; // that is, 10 seconds
public static final char MASK = '#'; // to mask out chars that are
// not to be seen by the player
public static void main(String[] args)
{
int i;
String clear;
String begin;
String puzzle_answer;
String presentation;
String guess;
// keyboard stream
Scanner sc = new Scanner(System.in);
// to start, clear the screen using the "clear_screen"
// method defined below.
System.out.println("hit any key to continue");
begin = sc.nextLine();
clear_screen();
// get the puzzle answer from the first user (the "host").
System.out.println("Host please enter the word for the player");
puzzle_answer = sc.nextLine();
// clear the screen so the second user (the player)
// does not see the answer.
clear_screen();
// construct the presentation string, that is, the
// answer string with all chars but 'r', 's', 't',
// 'l', 'n', 'e' and whitespace masked out.
puzzle_answer = puzzle_answer.replace('R',MASK);
puzzle_answer = puzzle_answer.replace('S',MASK);
puzzle_answer = puzzle_answer.replace('T',MASK);
puzzle_answer = puzzle_answer.replace('L',MASK);
puzzle_answer = puzzle_answer.replace('N',MASK);
puzzle_answer = puzzle_answer.replace('E',MASK);
puzzle_answer = puzzle_answer.replace('r',MASK);
puzzle_answer = puzzle_answer.replace('s',MASK);
puzzle_answer = puzzle_answer.replace('t',MASK);
puzzle_answer = puzzle_answer.replace('l',MASK);
puzzle_answer = puzzle_answer.replace('n',MASK);
puzzle_answer = puzzle_answer.replace('e',MASK);
// display the presentation string and give the
// player 10 seconds to look at it. (Use the
// "pause" method below to pause the program
// for the 10 seconds.)
System.out.println(puzzle_answer);
pause(TIME_LIMIT);
// Now, clear the screen again and get the player's guess.
clear_screen();
guess = sc.nextLine();
// compare the guess to the puzzle answer.
if(guess.equalsIgnoreCase(puzzle_answer))
System.out.println("You win $100,000!");
else
{
System.out.println("The answer was: " + puzzle_answer + '.');
System.out.println("Sorry, you'll have to settle " +
"for the rice-a-roni.");
}
} // end main
//////////////////////////////////////////////////////////////
public static void clear_screen()
{
// This method clears the screen
System.out.print("\033c");
} // end clear_screen
//////////////////////////////////////////////////////////////
public static void pause(long duration)
{
// This method implements a pause of "duration"
// milliseconds
try
{
Thread.sleep(duration);
}
catch (InterruptedException ie)
{
// do nothing
}
} // end pause
//////////////////////////////////////////////////////////////
}
My first problem is that it replaces the answer user one enters with the one with the letters replaced by "#". I know that it has something to do with puzzle_answer being used to be the one displayed with the "#". Presentation was the one that was supposed to be used for that. When I tried to get "puzzle_answer" string to be the same as "presentation" string it showed up with an error. Also how would I get it so the user guesses individual characters. Sorry for the book and thank you for any assistance. Maybe even one or two of you users may even recognize this.