-
Jul 27th, 2011, 10:18 AM
#1
Thread Starter
Junior Member
Very simple hangman game.
Hey!
I noticed that there are already a couple of these on this forum, but I just wanted some feedback on it. And imo it's the simplest one here
I also wrote a tutorial on how to do it (somewhat in progress) http://visualstudiotutorials.blogspo...n-game-in.html
Attachment 85304
Last edited by deus; Aug 8th, 2011 at 03:26 PM.
-
Jul 27th, 2011, 02:11 PM
#2
Re: Very simple hangman game.
To make life easier on some people, why not embed it is a resource and read the dictionary from there? Or better yet, include it in the directory of the application?
Also, I'd recommend a List(Of String) for the dictionary list instead of an array, but that's just a personal preference
As for your r.Next(), you could use something like:
Code:
r.Next(0, words.GetUpperBound(0))
That way if you ever modify the dictionary, you won't have to worry about getting out of bound errors and have to keep changing the code for small word addition/subtractions.
Also, if your label is not in the front (I had that issue in my hangman), just call the .BringToFront() method in your code. It'll do the exact same thing
Anyways, pretty good beginner tutorial on the hangman game. I look forward to seeing you improve! Looks like you were farther ahead of me when I had 18 posts
Last edited by formlesstree4; Jul 27th, 2011 at 02:12 PM.
Reason: Fixing smileys..
-
Jul 27th, 2011, 02:15 PM
#3
Thread Starter
Junior Member
Re: Very simple hangman game.
Originally Posted by formlesstree4
To make life easier on some people, why not embed it is a resource and read the dictionary from there? Or better yet, include it in the directory of the application?
Also, I'd recommend a List(Of String) for the dictionary list instead of an array, but that's just a personal preference
As for your r.Next(), you could use something like:
Code:
r.Next(0, words.GetUpperBound(0))
That way if you ever modify the dictionary, you won't have to worry about getting out of bound errors and have to keep changing the code for small word addition/subtractions.
Also, if your label is not in the front (I had that issue in my hangman), just call the .BringToFront() method in your code. It'll do the exact same thing
Anyways, pretty good beginner tutorial on the hangman game. I look forward to seeing you improve! Looks like you were farther ahead of me when I had 18 posts
Thanks, it's nice to hear that And thanks for the tips.
how do I include the dictionary in the build? I tried putting it in the resources folder but I didn't know how to include it in my code.
-
Jul 27th, 2011, 02:16 PM
#4
Re: Very simple hangman game.
In VB, you would call it with My.Resources.NameOfResource
It gets returned...as a String I believe. There's a way around that to make it into a List(Of String), I just don't have the code on me at the moment sadly...
-
Jul 27th, 2011, 02:19 PM
#5
Thread Starter
Junior Member
Re: Very simple hangman game.
Originally Posted by formlesstree4
In VB, you would call it with My.Resources.NameOfResource
It gets returned...as a String I believe. There's a way around that to make it into a List(Of String), I just don't have the code on me at the moment sadly...
hmm... that's what I tried last time and it didn't work (doesn't find it).
-
Jul 27th, 2011, 02:20 PM
#6
Re: Very simple hangman game.
Originally Posted by deus
hmm... that's what I tried last time and it didn't work (doesn't find it).
Interesting...well I don't know. I'd have to see what VS is doing. This is...what version? 2010?
-
Jul 27th, 2011, 02:21 PM
#7
Thread Starter
Junior Member
Re: Very simple hangman game.
Originally Posted by formlesstree4
Interesting...well I don't know. I'd have to see what VS is doing. This is...what version? 2010?
Yup 2010. I haven't looked into it too much though.
-
Aug 4th, 2011, 03:41 PM
#8
Re: Very simple hangman game.
I created a small hand man game a long time ago. Might find some parts useful
http://www.planet-source-code.com/vb...8229&lngWId=10
I used auto generated labels that are created and assigned values depending on the resource files word selection.
Long and winded to code.....
Code:
Select Case DirectCast(sender, Button).Name
Case "Button1"
Button1.Enabled = False
a = "a"
labelcheck()
Case "Button2"
Button2.Enabled = False
a = "b"
Mine....
vb Code:
Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles btnA.Click, btnB.Click, btnC.Click, btnD.Click, btnE.Click, btnF.Click, btnG.Click, _ btnH.Click, btnI.Click, btnJ.Click, btnK.Click, btnL.Click, btnM.Click, btnN.Click, btnO.Click, _ btnP.Click, btnQ.Click, btnR.Click, btnS.Click, btnT.Click, btnU.Click, btnV.Click, btnW.Click, _ btnX.Click, btnY.Click, btnZ.Click ' Has the user reached max try's? ' check here ........ DirectCast(sender, Button).Enabled = False ' Check letter pressed is in our word. IsletterPressedInHangmansWord(DirectCast(sender, Button).Text) End Sub Private Sub IsletterPressedInHangmansWord(ByVal letter As String) For Each c As Control In gbHangmansWords.Controls If c.Text.ToUpper = letter Then ' do task here ....... End If Next End Sub
Last edited by ident; Aug 4th, 2011 at 03:51 PM.
-
Aug 4th, 2011, 04:09 PM
#9
Thread Starter
Junior Member
Re: Very simple hangman game.
I like the features of your version.
I decided not to use dynamically created labels for the sake of the tutorial that I wrote. I wanted it to be as easy to create as possible, but if I were to create one for my own purposes it would probably have been smarter to create it with dynamic labels.
-
Aug 8th, 2011, 03:18 PM
#10
Fanatic Member
Re: Very simple hangman game.
deus I noticed that your zip file has the obj and bin folders in there with the .exe files inside them. I recently asked about posting in the codebank and was told you should remove the bin and obj folders. If someone opens the solution those folders are generated with all their files but that's the way they want it.
Make as many mistakes as you can as quickly as you can. We want to make sure that we make a great enough number of mistakes in a given amount of time so that we can be successful.
"Persistence is the magic of success." Paramahansa Yogananda
-
Aug 8th, 2011, 03:27 PM
#11
Thread Starter
Junior Member
Re: Very simple hangman game.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|