|
-
Oct 26th, 2004, 06:12 PM
#1
Thread Starter
New Member
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.
-
Oct 26th, 2004, 06:49 PM
#2
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.
-
Oct 26th, 2004, 08:18 PM
#3
Hyperactive Member
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
-
Oct 27th, 2004, 12:54 PM
#4
Thread Starter
New Member
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:
'sets number of visible lbl boxes to number of letters in word
Dim lblnumber As Integer
For lblnumber = 0 To Wordlength
Label1(lblnumber).Visible = True
Next
'sets number of invisible boxes to 10 - wordlength
Dim invisible As Integer
invisible = 10 - (Wordlength)
For invisible = Wordlength To 10
Label1(invisible).Visible = False
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.
-
Oct 27th, 2004, 01:35 PM
#5
Thread Starter
New Member
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.
-
Oct 27th, 2004, 02:01 PM
#6
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
-
Oct 27th, 2004, 02:23 PM
#7
Thread Starter
New Member
k here is most of what i have
VB Code:
Private Sub cmdnew_Click()
'picks random word from list
Dim Wordlist(1 To 20) As String
Dim Wordlength As Integer
Dim TheWord As String
Wordlist(1) = "hello"
Wordlist(2) = "jackal"
Wordlist(3) = "house"
Wordlist(4) = "mother"
Wordlist(5) = "epiphany"
Wordlist(6) = "linux"
Wordlist(7) = "speakers"
Wordlist(8) = "integer"
Wordlist(9) = "scool"
Wordlist(10) = "marriott"
Wordlist(11) = "ruler"
Wordlist(12) = "revolution"
Wordlist(13) = "lamp"
Wordlist(14) = "literacy"
Wordlist(15) = "pixel"
Wordlist(16) = "camera"
Wordlist(17) = "conehead"
Wordlist(18) = "smoke"
Wordlist(19) = "thought"
Wordlist(20) = "fridge"
'defines random as a random number
random = CInt(Int((20 * Rnd()) + 1))
'defines theword as a random word from the wordlist
TheWord = (Wordlist(random))
'defines wordlength as the length of the random word chosen
Wordlength = Len(TheWord)
'Test code to keep handy:
'msgbox test for word and wordlength
'MsgBox TheWord & " has " & Wordlength & " characters!"
'lbltheword.Caption = "This word is " & Wordlength & " letters long."
'lbltheword.FontUnderline = True
'image appear test
'Dim o As Integer
'For o = 0 To 7
'hangman(o).Visible = True
'Next
'sets number of visible lbl boxes to number of letters in word
Dim lblnumber As Integer
For lblnumber = 0 To Wordlength
lblunderscore(lblnumber).Visible = True
Next
'sets number of invisible boxes to 10 - wordlength
Dim invisible As Integer
invisible = 10 - (Wordlength)
For invisible = Wordlength To 10
lblunderscore(invisible).Visible = False
Next
'resets YOU WIN to invisible
lblwin.Visible = False
'extracts charater from chosen letter lbl and finds it in theword.
End Sub
VB Code:
Private Sub Form_Load()
'make all hangmen invisible
Dim i As Integer
For i = 0 To 7
hangman(i).Visible = False
Next
'make YOU WIN invisible
lblwin.Visible = False
'sets lblboxes to false visible upon frm load
Dim lbl As Integer
For lbl = 0 To 10
lblunderscore(lbl).Visible = False
Next
'makes the sequence of words random
Randomize
End Sub
-
Oct 27th, 2004, 02:30 PM
#8
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.
-
Oct 27th, 2004, 02:34 PM
#9
Thread Starter
New Member
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
-
Oct 27th, 2004, 03:06 PM
#10
the code that I posted above will search letter by letter, and replace the underscores with the correct letter. Just substitute your variable names.
-
Oct 27th, 2004, 05:16 PM
#11
Thread Starter
New Member
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
-
Oct 27th, 2004, 06:54 PM
#12
Thread Starter
New Member
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.
-
Oct 27th, 2004, 11:48 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|