|
-
Feb 2nd, 2001, 08:38 PM
#1
Thread Starter
Member
Im trying to make a hangman game. I have a problem figuring out how to subtract 10 points from your total amount (100) each time the letter doesnt match the word.
Also, when the phrase has 2 words like "I AM", how do you eliminate space so that "space" wont count as a letter.
The last thing I have a problem with is: How can i get a message box saying that you won when u guessed all the letters 1 by 1 without typing the whole word in the inputbox? Oh and when someone clicks on cancel button of input box, how do u make the msgbox saying that you quit the game and after you click on ok, the game will start again?
Thanks alot!
Private Sub cmdPlayGame_Click()
Const strTitle As String = "Tom's Hangman"
Const strPrompt As String = "Enter a letter and press OK to check if it matches. Enter * to solve."
Const strSentinel As String = "*"
Dim strSecretword As String
Dim strLength As String
Dim strGuess As String
Dim strGuessedsofar As String
Dim intPosition As Integer
Dim intGuesses As Integer
Dim intPoints As Integer
strSecretword = "captain america"
strLength = Len(strSecretword)
strGuessedsofar = String(strLength, "-")
lblWord.Caption = strGuessedsofar
intGuesses = 0
intPoints = "500"
lblPoints.Caption = intPoints
Do While strGuess <> strSentinel
intGuesses = intGuesses + 1
For intPosition = 1 To strLength
If StrComp(strGuess, Mid(strSecretword, intPosition, 1), vbTextCompare) = 0 Then
Mid(strGuessedsofar, intPosition, 1) = strGuess
End If
Next intPosition
lblWord.Caption = strGuessedsofar
strGuess = InputBox(strPrompt, strTitle)
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 " & intGuesses & " guesses to figure out the word"
Else
MsgBox "You loose. Press OK to display word"
End If
lblWord.Caption = strSecretword
End Sub
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
|