|
-
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
-
Feb 3rd, 2001, 12:39 AM
#2
Lively Member
Answer
1st question:
I'm assuming intPoints is the points that u wanna subtract from.
intPoints = intPoints - 10
2nd question:
Dim intPlace As Integer
Dim strWord As Integer
strWord = "I AM"
intPlace = InStr(1, strWord, " ")
strWord = Left(strWord, intPlace - 1) + Right(strWord, Len(strWord) - intPlace)
I know there are easier ways to do this and I tried to get it to loop but I'm having a memory block and can't remember that at the moment. Maybe someone else can help you with that.
3rd question:
if [win conditions] Then
MsgBox "You have won the game"
Call [SetNewGame]
End If
4th question:
If InputBox("Type something in") = vbCancel Then
MsgBox "The game will now exit"
End
End If
-
Feb 3rd, 2001, 12:51 PM
#3
Thread Starter
Member
Where do i put tho?
if [win conditions] Then
MsgBox "You have won the game"
Call [SetNewGame]
End If
Oh, and when i put points under fornext loop, it substract -10 anyway, wheather the letter appears or not. How do i chande it?
-
Feb 3rd, 2001, 07:31 PM
#4
Lively Member
You can put the if-then statement wherever you need to check to see if the user has won the game. The points will only be subtracted during the for-next loop if you put a code in the loop to subtract them. You can change this by taking out the code that subtracts points.
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
|