This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hangman game

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I wanted to work on a hangman game...

1.) First, the game has to have an array of words or phrases from which it picks one at random.
2.) It prints out rows of dashes which indicate each letter (if there is more than one word, there should be a space.)
The user must guess a letter one at a time. The program will then diplay the row of dashes with the letter showing if its is containted within the word. The user has 10 chances, after that, game over...If they are asked if they want to play again, and the program randomly selects another word.
The program must keep track of letters used already, so that the letters are not reused.
Its something like this:

Hang man: ---
Guess a letter: A
Letters used: A
Hangman: ---
Guess a letter: o
Letters used: A, O
Hangman: -o-
Guess a letter: Y
Letters used: A, O,Y
Guess a letter: t
Letters used: A,O,T,Y
Get the jist of it? Well...I know I have to declare some kind of array and it has to be in some loop, a while loop perhaps. And the 10 turns must be declared as an int variable, but after that I'm sketchy with how to replace the dashes with the correct letters used and how to keep track of the letters the user inputs.
What classes and methods are helpful? I'm in a beginner's programming class and this is an assignment. I'm pretty new at this Java stuff, so PULLLEEEASSEE can anyone give me a hand with some sort of code as to how to go about this program?
Any help will be greatly appreciated. Thank you very much...
Please respond as soon as possible...
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Noneyo Biznezz",
Sorry, but fictitious names are not allowed at the Ranch.
Please edit your profile so that your display name is valid. It will also help you get better responses.
Accounts with invalid display names get deleted without warning, but what may be worse in your case is that people won't take you seriously. Your display name must be two words: your first name, a space, then your last name, and fictitious names are not allowed.
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start breaking your problem down into steps and write code that looks like the steps. I think this captures the rules of the game:

Now that won't compile yet, but just comment it out for a sec. Can you imagine what might be in some of those other methods? A neat modern practice is to write tests before you even write code. What if the first thing you wrote in main() was:

See how you can verify the little methods are working before you try to put them together? Writing little bitty methods that work is a lot of fun. Writing a lot of them to get your program done is even more fun. Hope that helps!
BTW: If you really love this way of building programs, look at JUnit is a framework for writing tests like I showed above. It helps you get the tests out of your main() into a nice structure, automates running bunches of tests and displays the results nicely. It's not day-one beginner stuff, but it is a cool way of working.
[ December 02, 2003: Message edited by: Stan James ]
    Bookmark Topic Watch Topic
  • New Topic