Results 1 to 7 of 7
Thread: Help with a word guessing game.
- 04-23-2010, 04:07 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 4
- Rep Power
- 0
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 04:08 AM.
- 04-23-2010, 06:01 AM #2
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
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 ExpIf my answer helped you. Please click my "REP" button and add a comment
Have a Good Java Coding :)
- 05-04-2010, 03:56 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 4
- Rep Power
- 0
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.
- 05-04-2010, 04:09 AM #4
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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:
and the latter is much easier to read, don't you think?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(); } }); } }
- 05-04-2010, 05:09 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 05-19-2010, 04:07 AM #6
Member
- Join Date
- Apr 2010
- Posts
- 4
- Rep Power
- 0
I know it's a bit late but thanks for explaining the tags for me curmudgeon. Yes it is much easier to read.
- 05-19-2010, 04:22 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
No worries. Please try to do that next time onwards. Good luck :)
Similar Threads
-
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
guessing game help
By yasmin k in forum AWT / SwingReplies: 4Last Post: 10-31-2009, 05:37 PM -
guessing game using GUI
By yasmin k in forum New To JavaReplies: 1Last Post: 10-26-2009, 12:13 PM -
2D strategy game or 2D war game
By led1433 in forum Java 2DReplies: 5Last Post: 02-10-2009, 06:00 AM -
The 3 Word Story [Mini Game]
By Eku in forum Forum LobbyReplies: 90Last Post: 11-16-2008, 09:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks