• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Word guessing game

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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--
 
What's a year in metric? Do you know this metric stuff tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic