wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Word guessing game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Word guessing game" Watch "Word guessing game" New topic
Author

Word guessing game

mohsin shahzad
Greenhorn

Joined: Dec 28, 2002
Posts: 6
Hi im working on an assignment "Word guessing game". any1 who can help me or who already made this plzzz send me.
the requirements are
user will try to guess a word that system randomly generates.
his tries will be responded as
Example

"Mohsin" (The guessing word)
Mhgsah (user types)
11 (System response)

these digits shows the 1 = position of the accurate char.
and other 1= correct char found in the string

the main thing that is disturbing .. is how to make this through the network api. mean users can play it on a network.
any1 who can do it plzzz help me.
i'll be very thankful


Mohsin Shahzad
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'd break this into very small problems. Do you know how to generate a string of random characters? Do you know the compare rules that will give you the answer 11? Get these things working in a simple program that takes a guess word from the console before you worry about the network part.

AFTER those things are working, take a look at Sun's All About Sockets lessons. Run the examples down through the "client/server pair" and you'll start to see how to introduce the network. You might double check with your instructor if using sockets this way is ok.

If you get stuck, please post little bits of code as you go. Keep us posted on how it goes.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dale Seng
Ranch Hand

Joined: Mar 22, 2004
Posts: 275
This is "mastermind", and you should be able to find lots of examples of this on the internet. But I would say you would need to use the String.charAt() function in a loop to look at each letter.

for each letter, but not bigger than the length of the shorter string,
if secret one matched guess at same place
add one to your 'perfect' counter
remove the letter from both (so not to second count it)
back-off the counter by one, since you removed the letter
else if this secret letter matched anywhere in the guess (indexOf()>-1)
add one to your 'wrong position' counter

So String.substring(0,i) will take the first i characters of the string, and String.substring(i+1) will start at i+1 and go to the end. String.charAt(i) will give you a character you can compare.

--Dale--
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Word guessing game