Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 03-02-2005, 02:07 PM   #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
ecchikinetic is offline   Reply With Quote
Old 03-03-2005, 02:00 PM   #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"
ecchikinetic is offline   Reply With Quote
Old 03-04-2005, 03:21 AM   #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.
mattg2k4 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:18 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2