Results 1 to 9 of 9
Thread: Help with a Hangman Project
- 01-13-2012, 04:16 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
Help with a Hangman Project
Hi all,
So I am currently assigned a project where I have to make a basic hangman game where I am supposed to assign 50 words to a 250-value String class variable. I'm not really sure how I can implement such a thing or for that matter how a setup a String Class Variable like that. The only way I have ever done hangman before is by using a Dictionary class or an array. The book I have this project in is the Java al naturel book, which I'm somewhat impartial to. I originally learned java on my own over the summer by reading the Art & Science of Java which I like a lot more. That being said I have to use the other for the AP Computer Science class I am currently taking. Now the prompt is:
Hangman: Write Hangman as a subclass of BasicGame. Each word to be guessed should have five letters. Have a 250-letter String class variable that stores 50 possible words to choose at random.* Make sure to take some time thinking about how you plan to do this program BEFORE you start coding.
BasicGame is a simple frame for making Games for the chapter we are on, it has nothing of importance really to making hangman it just handles all the gui side of the program.
Now my main question is just how to I go about making the String Variable with 50 words in it and have the program choose a word randomly from that variable?
Thanks,
~Max
-
Re: Help with a Hangman Project
First of all, I have to say that in my opinion that is an extremely idiotic requirement, and I don't blame you of course, but whoever made this assignment. They should be taken down to the dungeon and strung up by their private packages. No array? No List? No file?
Anyway, I suppose you could create some variable
As to finding a random word -- I'll bet you can figure this one out -- why not give it a try and see what you can come up with?Java Code:public static final POSSIBLE_STRINGS = "after" + "doors" + ..... //ack!
- 01-13-2012, 04:33 AM #3
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
Re: Help with a Hangman Project
Yeah there are some really dumb assignments in this book, it isn't an awful book, The problem is it was published in 2002 and hasn't been updated so it is rather outdated. I really feel like this class is not teaching me anything, it isn't teaching me good programming practices or anything. It is really only teaching me how to deal with bad description and explanation to do the exercises and projects. And I'm assuming that if I do what you suggest I would have to do a s.substring call for a random increment of 5 values to get a word. I'm going to try that and see how it turns out.
Thanks,
~Max
-
Re: Help with a Hangman Project
You're welcome, and yeah, Random class has a great method, nextInt(...) that will let you get a random number between 0 and 50.
Luck!
- 01-13-2012, 05:09 AM #5
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
Re: Help with a Hangman Project
Okay so I have the choosing of the words set up and working correctly, but I'm somewhat stuck on how I would go about checking the user's guessed letter to see if it is part of the word. I have all the guessed letters going into a String so that it can be checked before a guess is added so no duplicates are added. But I'm not sure how to go about the checking. Any pointers you could give me?
Thanks
-
Re: Help with a Hangman Project
The best pointer I can think of: check out the String API. There are some very useful methods there that you can use.
- 01-13-2012, 05:16 AM #7
Re: Help with a Hangman Project
This is really ambiguous. Does 250-letter mean you have a single string with a length cap of 250 characters? If so, you would need to make sure your 50 words don't add up to more than 250 chars?Have a 250-letter String class variable that stores 50 possible words to choose at random.*
My guess is that the sentence is crap and the writer had no idea how to convey their meaning.
I would code this by making an array of strings with a capacity for 50 words. You could then choose a word at rand with the Random class. You could put all of this code in some kind of special 'Dictionary' class that you write yourself with nice accessor methods.
Good question, that sounds like an awful requirement. Unless all words were fixed length, you would need to know the offsets of each word. This is a terrible way to do this.Now my main question is just how to I go about making the String Variable with 50 words in it and have the program choose a word randomly from that variable?
- 01-13-2012, 05:20 AM #8
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
Re: Help with a Hangman Project
Alright thanks I will look at that.
Yeah the project sucks. All the words have to be 5 letter words to ensure that it is a 250 character max for the string. So I just have it doing random increments of 5 to pick a word. I really hate this book, the class is awful but I can't do much about it. I would have used a dictionary and an array as it makes more sense but I have to do it assuming I don't know how to do that yet as we haven't reached that chapter yet and the teacher has already accused me of cheating by using things ahead of what the book is teaching.
- 01-13-2012, 05:26 AM #9
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Re: Help with a Hangman Project
Yes, I missed the all words are five letters long requirement too when I read the post.If so, you would need to make sure your 50 words don't add up to more than 250 chars
Really it's an awful assignment. Name and shame, I say! Computer Science AP A, their web site is at Louisiana Virtual School - Welcome to LVS
Similar Threads
-
Hangman GUI project
By aviolently in forum Java GamingReplies: 7Last Post: 01-01-2012, 02:12 AM -
Hangman
By Feriscool in forum New To JavaReplies: 23Last Post: 05-17-2011, 06:54 PM -
hangman
By javaMike in forum Advanced JavaReplies: 2Last Post: 11-14-2009, 09:06 AM -
Hangman GUI help
By kurt in forum New To JavaReplies: 5Last Post: 05-22-2009, 10:22 AM -
Need help with Hangman!!!
By chinasome in forum New To JavaReplies: 10Last Post: 11-09-2008, 04:42 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks