Results 1 to 11 of 11

Thread: Very simple hangman game.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    23

    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.

  2. #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..

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    23

    Re: Very simple hangman game.

    Quote Originally Posted by formlesstree4 View Post
    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.

  4. #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...

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    23

    Re: Very simple hangman game.

    Quote Originally Posted by formlesstree4 View Post
    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).

  6. #6

    Re: Very simple hangman game.

    Quote Originally Posted by deus View Post
    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?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    23

    Re: Very simple hangman game.

    Quote Originally Posted by formlesstree4 View Post
    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.

  8. #8
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    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:
    1. Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    2.     Handles btnA.Click, btnB.Click, btnC.Click, btnD.Click, btnE.Click, btnF.Click, btnG.Click, _
    3.     btnH.Click, btnI.Click, btnJ.Click, btnK.Click, btnL.Click, btnM.Click, btnN.Click, btnO.Click, _
    4.     btnP.Click, btnQ.Click, btnR.Click, btnS.Click, btnT.Click, btnU.Click, btnV.Click, btnW.Click, _
    5.     btnX.Click, btnY.Click, btnZ.Click
    6.  
    7.         ' Has the user reached max try's?
    8.         ' check here ........
    9.  
    10.         DirectCast(sender, Button).Enabled = False
    11.  
    12.         ' Check letter pressed is in our word.
    13.         IsletterPressedInHangmansWord(DirectCast(sender, Button).Text)
    14.  
    15.     End Sub
    16.  
    17. Private Sub IsletterPressedInHangmansWord(ByVal letter As String)
    18.         For Each c As Control In gbHangmansWords.Controls
    19.             If c.Text.ToUpper = letter Then
    20.             ' do task here .......
    21.             End If
    22.         Next
    23.     End Sub
    Last edited by ident; Aug 4th, 2011 at 03:51 PM.

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    23

    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.

  10. #10
    Fanatic Member EntityX's Avatar
    Join Date
    Feb 2007
    Location
    Omnipresence
    Posts
    798

    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

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jun 2011
    Posts
    23

    Re: Very simple hangman game.

    Alright I've changed it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width