|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (5 bit)
Join Date: Feb 2005
Posts: 18
|
Hangman Problem
I'm trying to make hangman game from VB, it went fine but I need help with keeping track of the letters that the user has inputted in the inputbox. If the user has entered the same letter twice then a messagebox appears saying that the user has already guessed that letter. Heres the code:
Code:
Option Explicit
Private Sub cmdPlayGame_Click()
Const strSentinel As String = "!"
Dim strSecretWord As String, intSecretWordLength As Integer
Dim intNumberOfGuesses As Integer
Dim strGuess As String, strWordGuessedSoFar As String
Dim intLetterPos As Integer
strSecretWord = "magic"
intSecretWordLength = Len(strSecretWord)
strWordGuessedSoFar = String(intSecretWordLength, "-")
lblWord.Caption = strWordGuessedSoFar
intNumberOfGuesses = 0
strGuess = InputBox("Guess a letter (! to guess word)", "Hangman")
Do While strGuess <> strSentinel
intNumberOfGuesses = intNumberOfGuesses + 1
For intLetterPos = 1 To intSecretWordLength
If StrComp(strGuess, Mid(strSecretWord, intLetterPos, 1), vbTextCompare) = 0 Then
Mid(strWordGuessedSoFar, intLetterPos, 1) = strGuess
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 word")
End If
If StrComp(strGuess, strSecretWord, vbTextCompare) = 0 Then
MsgBox "You win! It took you " & intNumberOfGuesses & " guesses."
Else
MsgBox "You lose. Press OK to display secret word."
End If
lblWord.Caption = strSecretWord
End Sub
Private Sub cmdDone_Click()
Unload Me
End Sub
|
|
|
|
|
|
#2 |
|
Member (5 bit)
Join Date: Feb 2005
Posts: 18
|
Basically when a user puts the letter for example "a" then when the user inputs "a" again in the guess inputbox then a msgbox would display saying that "You have guessed this letter, Please try again"
|
|
|
|
|
|
#3 |
|
Member (10 bit)
Join Date: Jul 2002
Location: University of California, Santa Barbara
Posts: 800
|
I didn't see this new thread, so I replied to this in your last thread already.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|