Results 1 to 7 of 7
  1. #1
    The_Round_One is offline Member
    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Default 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.

    Java 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.
    Last edited by The_Round_One; 05-19-2010 at 05:08 AM.

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    First put your code in code tags. It is unclear :(
    Secondly the forum has games thread. It is quite good as for yours :)

    You can simply organize the answers code by putting down answers in array manner :)
    Check the regular expression classes to organize a simple word analyzing watch the link Reg Exp
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  3. #3
    The_Round_One is offline Member
    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Default

    Thanks for the reply. I wasn't looking for an answers array. I was looking for a way one player to enter a word and the other player guesses it with only a limited amount of letters displayed. I figured out what I had to do to get this. If you or anyone that stumbles across this thread wants to see the code just leave a message. Also what are tags? I leave comments with the " // " on my code to display a small description in comments. I don't regularly post in forums so if it's some forum thing could you please explain.

  4. #4
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Tags are ways to let the forum software know that you are posting code. You place the tag

    [code]

    on top of your code block and

    [/code]

    below your code block. This will change the appearance of posted code from this:
    public class ColourSlidersTest {
    private static void createAndShowUI() {
    JFrame frame = new JFrame("ColourSlidersTest");
    frame.getContentPane().add(new ColourSlidersGUI().getMainPanel());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    }

    public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    createAndShowUI();
    }
    });
    }
    }


    to this:
    Java Code:
    public class ColourSlidersTest {
      private static void createAndShowUI() {
        JFrame frame = new JFrame("ColourSlidersTest");
        frame.getContentPane().add(new ColourSlidersGUI().getMainPanel());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
            createAndShowUI();
          }
        });
      }
    }
    and the latter is much easier to read, don't you think?

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Webuser View Post
    You can simply organize the answers code by putting down answers in array manner :)
    Check the regular expression classes to organize a simple word analyzing watch the link Reg Exp
    I agreed with you. That's the most suitable way. While keeping the answers in an array, you can compare user inputs in many ways, still the fastest manipulations take place.

  6. #6
    The_Round_One is offline Member
    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Default

    I know it's a bit late but thanks for explaining the tags for me curmudgeon. Yes it is much easier to read.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 05:49 AM
  2. guessing game help
    By yasmin k in forum AWT / Swing
    Replies: 4
    Last Post: 10-31-2009, 06:37 PM
  3. guessing game using GUI
    By yasmin k in forum New To Java
    Replies: 1
    Last Post: 10-26-2009, 01:13 PM
  4. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 07:00 AM
  5. The 3 Word Story [Mini Game]
    By Eku in forum Forum Lobby
    Replies: 90
    Last Post: 11-16-2008, 10:01 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •