Need help with a certain part to a hangman game..

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2006
Posts: 1
Reputation: tk005x is an unknown quantity at this point 
Solved Threads: 0
tk005x tk005x is offline Offline
Newbie Poster

Need help with a certain part to a hangman game..

 
0
  #1
Jun 14th, 2006
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..

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdStart_Click()
  2. Const strSentinel As String = "!"
  3.  
  4. Dim intSecretWordLength As Integer
  5. Dim intNumberOfGuesses As Integer
  6. Dim intLetterPos As Integer
  7. Dim intInCorrectNumberOfGuesses As Integer
  8.  
  9. Dim intWordPickNumber
  10.  
  11. Dim strSecretWord As String
  12. Dim strGuess As String
  13. Dim strWordGuessedSoFar As String
  14.  
  15. intWordPickNumber = RndInt(1, 12)
  16.  
  17. strSecretWord = "Boat"
  18.  
  19. intSecretWordLength = Len(strSecretWord)
  20.  
  21. strWordGuessedSoFar = String(intSecretWordLength, "-")
  22. lblWord.Caption = strWordGuessedSoFar
  23.  
  24. intNumberOfGuesses = 0
  25. intInCorrectNumberOfGuesses = 0
  26.  
  27. Call ResetPic
  28.  
  29. strGuess = InputBox("Guess a letter (! to guess word)", "Hangman")
  30. Do While strGuess <> strSentinel
  31. intNumberOfGuesses = intNumberOfGuesses + 1
  32.  
  33. If lblWord.Caption = strSecretWord Then
  34. MsgBox "You win"
  35. Exit Sub
  36. End If
  37.  
  38. For intLetterPos = 1 To intSecretWordLength
  39. If StrComp(strGuess, Mid(strSecretWord, intLetterPos, 1), vbTextCompare) = 0 Then
  40. Mid(strWordGuessedSoFar, intLetterPos, 1) = strGuess
  41. Else
  42. *** Call CheckPic(strSecretWord) 'Guessed it wrong ****
  43.  
  44. End If
  45.  
  46. If lnRightLeg.Visible = True Then
  47. Exit Sub
  48. End If
  49.  
  50. Next intLetterPos
  51. lblWord.Caption = strWordGuessedSoFar
  52. strGuess = InputBox("Guess a letter (! to guess word)", "Hangman")
  53. Loop
  54.  
  55. If strGuess = strSentinel Then
  56. strGuess = InputBox("Guess the whole word")
  57. End If
  58.  
  59. If StrComp(strGuess, strSecretWord, vbTextCompare) = 0 Then
  60. MsgBox "You win."
  61. Else
  62. MsgBox "You lost press ok to see what the word was."
  63. lblWord.Caption = strSecretWord
  64. End If
  65. End Sub
  66. Sub ResetPic()
  67. shpHead.Visible = False
  68. shpRightHand.Visible = False
  69. shpLeftHand.Visible = False
  70. lnBody.Visible = False
  71. lnLeftArm.Visible = False
  72. lnRightArm.Visible = False
  73. lnRightLeg.Visible = False
  74. lnLeftLeg.Visible = False
  75. End Sub
  76.  
  77. Sub CheckPic(ByVal strSecretWord As String)
  78.  
  79. If shpHead.Visible = False Then
  80. shpHead.Visible = True
  81. ElseIf shpHead.Visible = True And lnBody.Visible = False Then
  82. lnBody.Visible = True
  83. ElseIf lnBody.Visible = True And lnRightArm.Visible = False Then
  84. lnRightArm.Visible = True
  85. ElseIf lnRightArm.Visible = True And lnLeftArm.Visible = False Then
  86. lnLeftArm.Visible = True
  87. ElseIf lnLeftArm.Visible = True And shpRightHand.Visible = False Then
  88. shpRightHand.Visible = True
  89. ElseIf shpRightHand.Visible = True And shpLeftHand.Visible = False Then
  90. shpLeftHand.Visible = True
  91. ElseIf shpLeftHand.Visible = True And lnLeftLeg.Visible = False Then
  92. lnLeftLeg.Visible = True
  93. ElseIf lnLeftLeg.Visible = True And lnRightLeg.Visible = False Then
  94. lnRightLeg.Visible = True
  95. MsgBox "You lost"
  96. lblWord.Caption = strSecretWord
  97. End If
  98. End Sub
  99. '*********************************************************************************************************
  100. 'Makes a random number
  101. 'Pre: Boundries with the lowest and highest number
  102. 'Post: one number that is generated from the boundries
  103. '************************************************************************************************************
  104. Function RndInt(ByVal intLow As Integer, ByVal intHi As Integer) As Double
  105.  
  106. RndInt = Int((intHi - intLow + 1) * Rnd + intLow)
  107.  
  108. End Function
Last edited by tk005x; Jun 14th, 2006 at 8:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 119
Reputation: agrothe is an unknown quantity at this point 
Solved Threads: 14
agrothe's Avatar
agrothe agrothe is offline Offline
Junior Poster

Re: Need help with a certain part to a hangman game..

 
0
  #2
Jun 15th, 2006
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
------------------------------------------------------------
If you see no coffee in my immediate vicinity, speak slowly and use small words....
ConnectNL Directory | Blog
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC