VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This is the updated version of hangman. It draws the hangman, has a random word generator (easy to

by James Nass (2 Submissions)
Category: Games
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Tue 14th March 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This is the updated version of hangman. It draws the hangman, has a random word generator (easy to add words), displays text for win or loss

API Declarations


'First off you need to create a blank label and call it lblSample, 2 command buttons, cmdplay and cmddone, and draw a hangman using lines for the body, arms, legs, circle for the head, x's for the eyes and little line on top of its head. Thats pretty much it. Except for a little lbl which along with the body should be invisible. call it lblrandom. I will submit it as a zip so it makes more sense

Rate This is the updated version of hangman. It draws the hangman, has a random word generator (easy to




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
Dim intRandom As Integer


lblRandom.Caption = Int(Rnd * 16)


If lblRandom.Caption = 1 Then strSecretWord = "chalkboard"
If lblRandom.Caption = 2 Then strSecretWord = "computer"
If lblRandom.Caption = 3 Then strSecretWord = "calendar"
If lblRandom.Caption = 4 Then strSecretWord = "printer"
If lblRandom.Caption = 5 Then strSecretWord = "paper"
If lblRandom.Caption = 6 Then strSecretWord = "ceiling"
If lblRandom.Caption = 7 Then strSecretWord = "door"
If lblRandom.Caption = 8 Then strSecretWord = "america"
If lblRandom.Caption = 9 Then strSecretWord = "backpack"
If lblRandom.Caption = 10 Then strSecretWord = "keyboard"
If lblRandom.Caption = 11 Then strSecretWord = "application"
If lblRandom.Caption = 12 Then strSecretWord = "randomize"
If lblRandom.Caption = 13 Then strSecretWord = "argument"
If lblRandom.Caption = 14 Then strSecretWord = "statement"
If lblRandom.Caption = 15 Then strSecretWord = "pavement"
If lblRandom.Caption = 16 Then strSecretWord = "technology"


strSecretWord = strSecretWord
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")

If intNumberOfGuesses = 3 Then shpHead.Visible = True
If intNumberOfGuesses = 4 Then linBody.Visible = True
If intNumberOfGuesses = 5 Then linLeftArm.Visible = True
If intNumberOfGuesses = 6 Then linRightArm.Visible = True
If intNumberOfGuesses = 7 Then linLeftLeg.Visible = True
If intNumberOfGuesses = 8 Then linRightLeg.Visible = True
If intNumberOfGuesses = 2 Then lineRope.Visible = True
If intNumberOfGuesses = 1 Then lineGallow.Visible = True
If intNumberOfGuesses = 9 Then linleftdash.Visible = True
If intNumberOfGuesses = 9 Then linRightDash.Visible = True
If intNumberOfGuesses = 10 Then lin2LeftDash.Visible = True
If intNumberOfGuesses = 10 Then lin2rightdash.Visible = True
If intNumberOfGuesses = 11 Then shpMouth.Visible = True
If intNumberOfGuesses = 12 Then linLeftFoot.Visible = True
If intNumberOfGuesses = 13 Then linRightFoot.Visible = True

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."
If intNumberOfGuesses = 0 Then MsgBox "You cheated"
If intNumberOfGuesses = 1 Then MsgBox "Perfect"
If intNumberOfGuesses = 2 Then MsgBox "Good Job"
If intNumberOfGuesses = 3 Then MsgBox "Fair"
If intNumberOfGuesses = 4 Then MsgBox "O.K."
If intNumberOfGuesses = 5 Then MsgBox "Decent"
If intNumberOfGuesses = 6 Then MsgBox "Poor"
If intNumberOfGuesses = 7 Then MsgBox "Whats wrong with you?"
If intNumberOfGuesses = 8 Then MsgBox "You are bad"
If intNumberOfGuesses = 9 Then MsgBox "Terrible"
If intNumberOfGuesses = 9 Then MsgBox "Bad"
If intNumberOfGuesses = 10 Then MsgBox "Your pretty stupid"
If intNumberOfGuesses = 11 Then MsgBox "Miss the Short bus today?"
If intNumberOfGuesses = 12 Then MsgBox "Go back to Preschool"
If intNumberOfGuesses = 13 Then MsgBox "Duuuuuhhhhh!?!?"
Else
    MsgBox "You lose. After " & intNumberOfGuesses & " guesses you got it wrong."
End If

    lblWord.Caption = strSecretWord
End Sub

Private Sub cmdDone_Click()
    Unload Me
End Sub



Private Sub Form_Load()
    Randomize
End Sub


Download this snippet    Add to My Saved Code

This is the updated version of hangman. It draws the hangman, has a random word generator (easy to Comments

No comments have been posted about This is the updated version of hangman. It draws the hangman, has a random word generator (easy to . Why not be the first to post a comment about This is the updated version of hangman. It draws the hangman, has a random word generator (easy to .

Post your comment

Subject:
Message:
0/1000 characters