Results 1 to 13 of 13

Thread: Newb Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    7

    Newb Help

    Im a really big n00b at this, im making a hangman game for a school project and have gotten quite stuck. I need to somehow make lable boxes (most likely in an array) that are purely underlines appear for the hidden letters. A random word is picked from a list (all of which i have already). I need the number of underlines to equal the number of letters in the random word (i have a somewhat basic code to GET the number of letters) and then once the user selects a correct letter i need to have the proper letters replace the underscores. This is very confusing for me and would appreciate some help.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    You'd use a control array. Array index = 0 is the 'template', if the word has 3 letters then you'd load label control instances label(1), label(2), label(3).

    Positioning them on the form is the tricky part. I suggest generating the labels in a picture box (You also have to set the parent property of the newly created instance of the label), adjusting the pic box width to fit the labels (including spaces between labels). And when that's done, simply center the pic box, rather than computing the position of each label based on a center.

  3. #3
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348
    what are you using to hold the words?

    Well what you could do to get the amount of underlines is

    Code:
     label1.caption = len(List1.text)
    That should make the label say the length of the selected word in the listbox. All you have to do is put this code wherever the random word is being selected.
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    7
    OK well i made 10 separate labels, each containing an underscore and used a loop to determine the number of visible labels like this


    VB Code:
    1. 'sets number of visible lbl boxes to number of letters in word
    2.     Dim lblnumber As Integer
    3.     For lblnumber = 0 To Wordlength
    4.     Label1(lblnumber).Visible = True
    5.     Next
    6.    
    7. 'sets number of invisible boxes to 10 - wordlength
    8.     Dim invisible As Integer
    9.     invisible = 10 - (Wordlength)
    10.     For invisible = Wordlength To 10
    11.     Label1(invisible).Visible = False
    12.     Next
    much thanks to the help of my patient friend, but now all of which have abandoned me due to "idiocy" so I have turned to the forums!
    Okay sorry to bother so much, but I have an array of labels each containing one letter of the alphabet, and then duplicated for the "jailed words" list of letters you've already guessed. I cannot even begin to fathom how i can possibly make the guessing letters work.
    I need to make the labels, when clikced, if found in the word randomly selected, replace the underscore of the appropriate spot to the word guessed.
    confused


    20min later.......
    awww common guys! i need help my friends have all but abaonded me since i asked so many questions
    Last edited by KevLeviathan; Oct 27th, 2004 at 01:26 PM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    7

    Unhappy

    okay rephrase?
    I need to take the letter from the lbl clicked and have the program search for this letter in theword ranomly selected. If it finds this letter, all instances of this letter in the word, inplace of the corresponding underscores will turn to this letter.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    Code:
    For x = 1 to len(word)
      If mid(word,x) = letter Then
         mid(newword,x) = letter
      endif
    Next x

    something like that?

    post your code, as I didn't know your var names, or how they're delared

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    7
    k here is most of what i have

    VB Code:
    1. Private Sub cmdnew_Click()
    2. 'picks random word from list
    3.     Dim Wordlist(1 To 20) As String
    4.     Dim Wordlength As Integer
    5.     Dim TheWord As String
    6.     Wordlist(1) = "hello"
    7.     Wordlist(2) = "jackal"
    8.     Wordlist(3) = "house"
    9.     Wordlist(4) = "mother"
    10.     Wordlist(5) = "epiphany"
    11.     Wordlist(6) = "linux"
    12.     Wordlist(7) = "speakers"
    13.     Wordlist(8) = "integer"
    14.     Wordlist(9) = "scool"
    15.     Wordlist(10) = "marriott"
    16.     Wordlist(11) = "ruler"
    17.     Wordlist(12) = "revolution"
    18.     Wordlist(13) = "lamp"
    19.     Wordlist(14) = "literacy"
    20.     Wordlist(15) = "pixel"
    21.     Wordlist(16) = "camera"
    22.     Wordlist(17) = "conehead"
    23.     Wordlist(18) = "smoke"
    24.     Wordlist(19) = "thought"
    25.     Wordlist(20) = "fridge"
    26.    
    27. 'defines random as a random number
    28.     random = CInt(Int((20 * Rnd()) + 1))
    29.    
    30. 'defines theword as a random word from the wordlist
    31.     TheWord = (Wordlist(random))
    32.    
    33. 'defines wordlength as the length of the random word chosen
    34.     Wordlength = Len(TheWord)
    35.    
    36.        
    37.        'Test code to keep handy:
    38.        'msgbox test for word and wordlength
    39.        'MsgBox TheWord & " has " & Wordlength & " characters!"
    40.    
    41.        'lbltheword.Caption = "This word is " & Wordlength & " letters long."
    42.        'lbltheword.FontUnderline = True
    43.    
    44.        'image appear test
    45.        'Dim o As Integer
    46.        'For o = 0 To 7
    47.        'hangman(o).Visible = True
    48.        'Next
    49.    
    50.    
    51. 'sets number of visible lbl boxes to number of letters in word
    52.     Dim lblnumber As Integer
    53.     For lblnumber = 0 To Wordlength
    54.     lblunderscore(lblnumber).Visible = True
    55.     Next
    56.    
    57. 'sets number of invisible boxes to 10 - wordlength
    58.     Dim invisible As Integer
    59.     invisible = 10 - (Wordlength)
    60.     For invisible = Wordlength To 10
    61.     lblunderscore(invisible).Visible = False
    62.     Next
    63. 'resets YOU WIN to invisible
    64.     lblwin.Visible = False
    65.  
    66. 'extracts charater from chosen letter lbl and finds it in theword.
    67.  
    68.  
    69. End Sub

    VB Code:
    1. Private Sub Form_Load()
    2.     'make all hangmen invisible
    3.     Dim i As Integer
    4.     For i = 0 To 7
    5.     hangman(i).Visible = False
    6.     Next
    7.    
    8.     'make YOU WIN invisible
    9.     lblwin.Visible = False
    10.    
    11.     'sets lblboxes to false visible upon frm load
    12.     Dim lbl As Integer
    13.     For lbl = 0 To 10
    14.     lblunderscore(lbl).Visible = False
    15.     Next
    16.    
    17.     'makes the sequence of words random
    18.     Randomize
    19. End Sub

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    if you are using 0 to wordlength, then don't you want it to be wordlength - 1? if not, then you want to start at 1, as you are looping more times then there are letters in the word.

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    7
    well thats what I thought, but it was making one short underscore.... so i changed the 1 to 0 and now that function works correctly. Now i have to scratch my head at how to make the letters work...
    my friend said to use InStr function but im really confused

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    the code that I posted above will search letter by letter, and replace the underscores with the correct letter. Just substitute your variable names.

  11. #11

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    7
    oh sorry im so unorganized, lol im doing this half at school and half at home. Well i managed to get some more thing working while at school, now the only thing left to do is make the hangman pictures appear each time you guess an incorrect letter and bold it in the "jailed words" box, but im having a tough time making the "YOU WIN!" lbl appear after the word is full.... hmm il think some more lol i seem to be figuring out most stuff without forums thx for help though

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    7
    All is going well! I'm done except for one thing: I cant get the hangman pictures to stop appearing after you've lost. I have a series of 8 pictures, each with another part of the body added. They appear as you guess incorrect letters and then once it equals 8 a lbl called lbllose and a message box comes up telling you you've lost. Similar thing for You've Won, but it records the number of correct guesses. But, after you've won or lost, you can still click on letters to guess and when you guess an incorrect one the program has an error because it cannot load the next image in the loop because it doesnt exist. help here would be excellent, some way to disable all functions except the "New Game" button.

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    Code:
    btnCommand.Visible = False
    just replace btnCommand with the name of your command button.

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