Question: Create a Visual Basic application for the classic game \"Hangman\". Cr
ID: 3878629 • Letter: Q
Question
Question: Create a Visual Basic application for the classic game "Hangman".
Create a Visual Basic application for the classic game "Hangman". APPLICATION MUST LOOK EXACTLY LIKE BELOW PICTURE(S), MORE DETAILS BELOW The below pictures dictate exactly how the application/game and the user interface should look. When starting the application, user should see Screen 1. The X's indicate that a new game session has yet to be started AND the keyboard is inactive in this mode. Pressing the "Start Game" button will enable playing mode (which is what Screen 2 showcases).
Screen 1 (below):
Upon clicking Start Game, a random word no more than 16 characters long should be selected. The hyphens (-) shown below in Screen 2 represent how many characters the randomized word is. Selection of words can be any amount, so long as they meet the "no more than 16 characters" rule.
Screen 2 (below):
User will then click on letters to try and guess what the word is. Every time a letter is selected, it will count as one mark in the upper-left hand "0 tries" box, as well as display within where the letter is in the word itself. Once the word is correctly guessed (and the number of tries is also still accumululating), user can then click to the "Stop Game" button to go back to the first screen (Screen 1) and click on "Start Game". Of course, the user can stop the game at any time they choose, not only when a game is finished. Example of finished game below (Screen 3)
Welcome to Hangman L M N 0 Start GameExplanation / Answer
Public Class frmHang
Dim strWord(10) As String 'array of answer cchoices
Dim strAnswer As String 'the correct answer
Dim intX As Integer 'general purpose variable
Dim intPicIndex As Integer 'current image on display
Private Sub frmHang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim intLp As Integer 'used in for loop
Randomize()
'load array with selection of answers
strWord(0) = "original copy"
strWord(1) = "sensitive skin"
strWord(2) = "bad arguement"
strWord(3) = "procede with care"
strWord(4) = "math function"
strWord(5) = "fifth demension"
strWord(6) = "determined mind"
strWord(7) = "out of character"
strWord(8) = "anywhere you want"
strWord(9) = "honest statement"
strWord(10) = "computer hacker"
'randomly select an answer
intX = Rnd(200) * 10
strAnswer = strWord(intX)
'get the length of the selected answer
intX = strAnswer.Length
'create a hidden display of the answer
If intX > 0 Then
For intLp = 1 To intX
If Mid(strAnswer, intLp, 1) <> " " Then
lblWord.Text += "_ "
Else
lblWord.Text += " "
End If
Next
Else 'this should never happen
lblWord.Text = "Zero Error"
End If
intPicIndex = 0 'set the current image for display
Debug.Print("The word or phrase is: " & strAnswer) 'outputs the correct answer for bug issues
End Sub
Private Sub cmdGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGuess.Click
Dim strUGuess As String 'user's guess
strUGuess = txtGuess.Text.ToLower 'convert to lower case
If strUGuess = strAnswer Then
lblMsg.Text = "Correct You're free to go, pilgrim."
pbHang.Image = imlHang.Images.Item(0)
'call aniWalk()
Else
lblMsg.Text = "Sorry... Now you must pay the price."
pbHang.Image = imlHang.Images.Item(10)
End If
'Game Over --- disable further play
cmdGuess.Enabled = False
txtGuess.Enabled = False
cmbLetter.Enabled = False
End Sub
[color=#FF0000]
Private Sub cmbLetter_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbLetter.SelectedValueChanged
'this sub excutes when a user selects a character
' from the combo box
Dim strChar As String 'used for character guessed
Dim intCharLen As Integer 'location of character found
Dim strDisplay As String 'used to update the displayed word
Dim intPutChar As Integer 'location to place character in display
Dim strTemp As String 'temp variable for updating characters
Dim intListCount As Integer 'count of guesses in list box
Dim blnCharUsed As Boolean 'true if character has already been used
Dim blnFlag As Boolean 'general flag
'initialize variables
strChar = cmbLetter.Text 'get the letter selected
strTemp = strAnswer
intListCount = lstGuesses.Items.Count 'number of guesses so far
blnCharUsed = False
'see if this character has been used before
For intX = 1 To intListCount
If lstGuesses.Items.Item(intX - 1) = strChar Then
blnCharUsed = True
End If
Next
If blnCharUsed Then
MsgBox("You've already used " & strChar & ".", , "Input Error")
Else
lstGuesses.Items.Add(strChar) 'add this one to the list
intCharLen = strTemp.Length
blnFlag = False 'set to true if the char is found in answer
'change the displayed word on the form
For intX = 1 To intCharLen
If Mid(strTemp, intX, 1) = strChar Then
blnFlag = True 'found one
strDisplay = lblWord.Text
intPutChar = intX * 2 - 1
Mid(strDisplay, intPutChar) = strChar
lblWord.Text = strDisplay
End If
Next
If blnFlag Then 'char found -- see if word was solved
strDisplay = lblWord.Text
intCharLen = strDisplay.Length
'see if any underscores are left
For intX = 1 To intCharLen
If Mid(strDisplay, intX, 1) = "_" Then
blnFlag = False 'word was not solved
End If
Next
If blnFlag = True Then 'word was solved
lblMsg.Text = "You're free to go, pilgrim."
pbHang.Image = imlHang.Images.Item(0)
cmdGuess.Enabled = False
txtGuess.Enabled = False
cmbLetter.Enabled = False
'call aniWalk()
End If
Else 'char was not found
intPicIndex += 1 'advance to the next picture
pbHang.Image = imlHang.Images(intPicIndex)
If intPicIndex = 10 Then
lblMsg.Text = "Sorry... Now you must pay the price."
cmdGuess.Enabled = False
txtGuess.Enabled = False
cmbLetter.Enabled = False
End If
End If
End If
End Sub[/color]
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.