| | |
Need help with a certain part to a hangman game..
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2006
Posts: 1
Reputation:
Solved Threads: 0
I got most of it done except one part to it. I also took out the part that picks the word.. I used the compare string command for each guess to see if the letter matches with what the user put in or not.
But I wanted it so that everytime the user makes a wrong guess, then a head or arm or whatever part of the hangman picture shows up till they loose. I tried making a counter paired with a case statement in the else part and also trying to make another If statement with it = 1 or -1 with the compare string function.
Problem is that when it does work, even though its supposed to draw the head first then the arm etc, but instead it draws the head arms etc all it once. It seems like the For Loop is messing it up because it is doing it for the length of the string but I'm not sure what else to do, I tried putting in the Next but that didn't help. I tried to think of something else mathematically but the length of the strings are all different so I'm stuck.
If possible would likethe solution to be really basic stuff that is in the program right now so that I can understand.
Thanks for the help....
I put the *** for where the problem is..
But I wanted it so that everytime the user makes a wrong guess, then a head or arm or whatever part of the hangman picture shows up till they loose. I tried making a counter paired with a case statement in the else part and also trying to make another If statement with it = 1 or -1 with the compare string function.
Problem is that when it does work, even though its supposed to draw the head first then the arm etc, but instead it draws the head arms etc all it once. It seems like the For Loop is messing it up because it is doing it for the length of the string but I'm not sure what else to do, I tried putting in the Next but that didn't help. I tried to think of something else mathematically but the length of the strings are all different so I'm stuck.
If possible would likethe solution to be really basic stuff that is in the program right now so that I can understand.
Thanks for the help....
I put the *** for where the problem is..
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub cmdStart_Click() Const strSentinel As String = "!" Dim intSecretWordLength As Integer Dim intNumberOfGuesses As Integer Dim intLetterPos As Integer Dim intInCorrectNumberOfGuesses As Integer Dim intWordPickNumber Dim strSecretWord As String Dim strGuess As String Dim strWordGuessedSoFar As String intWordPickNumber = RndInt(1, 12) strSecretWord = "Boat" intSecretWordLength = Len(strSecretWord) strWordGuessedSoFar = String(intSecretWordLength, "-") lblWord.Caption = strWordGuessedSoFar intNumberOfGuesses = 0 intInCorrectNumberOfGuesses = 0 Call ResetPic strGuess = InputBox("Guess a letter (! to guess word)", "Hangman") Do While strGuess <> strSentinel intNumberOfGuesses = intNumberOfGuesses + 1 If lblWord.Caption = strSecretWord Then MsgBox "You win" Exit Sub End If For intLetterPos = 1 To intSecretWordLength If StrComp(strGuess, Mid(strSecretWord, intLetterPos, 1), vbTextCompare) = 0 Then Mid(strWordGuessedSoFar, intLetterPos, 1) = strGuess Else *** Call CheckPic(strSecretWord) 'Guessed it wrong **** End If If lnRightLeg.Visible = True Then Exit Sub End If Next intLetterPos lblWord.Caption = strWordGuessedSoFar strGuess = InputBox("Guess a letter (! to guess word)", "Hangman") Loop If strGuess = strSentinel Then strGuess = InputBox("Guess the whole word") End If If StrComp(strGuess, strSecretWord, vbTextCompare) = 0 Then MsgBox "You win." Else MsgBox "You lost press ok to see what the word was." lblWord.Caption = strSecretWord End If End Sub Sub ResetPic() shpHead.Visible = False shpRightHand.Visible = False shpLeftHand.Visible = False lnBody.Visible = False lnLeftArm.Visible = False lnRightArm.Visible = False lnRightLeg.Visible = False lnLeftLeg.Visible = False End Sub Sub CheckPic(ByVal strSecretWord As String) If shpHead.Visible = False Then shpHead.Visible = True ElseIf shpHead.Visible = True And lnBody.Visible = False Then lnBody.Visible = True ElseIf lnBody.Visible = True And lnRightArm.Visible = False Then lnRightArm.Visible = True ElseIf lnRightArm.Visible = True And lnLeftArm.Visible = False Then lnLeftArm.Visible = True ElseIf lnLeftArm.Visible = True And shpRightHand.Visible = False Then shpRightHand.Visible = True ElseIf shpRightHand.Visible = True And shpLeftHand.Visible = False Then shpLeftHand.Visible = True ElseIf shpLeftHand.Visible = True And lnLeftLeg.Visible = False Then lnLeftLeg.Visible = True ElseIf lnLeftLeg.Visible = True And lnRightLeg.Visible = False Then lnRightLeg.Visible = True MsgBox "You lost" lblWord.Caption = strSecretWord End If End Sub '********************************************************************************************************* 'Makes a random number 'Pre: Boundries with the lowest and highest number 'Post: one number that is generated from the boundries '************************************************************************************************************ Function RndInt(ByVal intLow As Integer, ByVal intHi As Integer) As Double RndInt = Int((intHi - intLow + 1) * Rnd + intLow) End Function
Last edited by tk005x; Jun 14th, 2006 at 8:00 pm.
Why not use a control array and a counter? Every time someone guesses wrong do:
count = count + 1
if NOT controlarray(count).visible and NOT count > Ubound(controlarray()) then
controlarray(count).visible = true
end if
Thats how I did a hangman game back in 98 on my brother's laptop while driving on family vacation from Winnipeg to Minniapolis
count = count + 1
if NOT controlarray(count).visible and NOT count > Ubound(controlarray()) then
controlarray(count).visible = true
end if
Thats how I did a hangman game back in 98 on my brother's laptop while driving on family vacation from Winnipeg to Minniapolis
------------------------------------------------------------
If you see no coffee in my immediate vicinity, speak slowly and use small words....
ConnectNL Directory | Blog
If you see no coffee in my immediate vicinity, speak slowly and use small words....
ConnectNL Directory | Blog
![]() |
Similar Threads
- Writing a Hangman game (C++)
- Hangman Game Help!! (Java)
- plz help with game (Pascal and Delphi)
- Homework Help - Hangman Game (VB.NET)
- Help with while loop for hangman project (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Control button Click event
- Next Thread: Opening a form on click event in a different File
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





