I put a do while statement where it says 2nd player enters letters. It is suppose to stop user 2 from putting in numbers.If they do, message should pop up,"enter letters only".. It also should not prompt the hangman body to go forth due to it being wrong letter nor should it go to the incorrect letter box. All it should do it prompt a message and ask to enter a letter again after that.
I can not get this to work. Please look at my code. This assignment is due tomorrow.I've been working hard on it.I hope I found a VB site that actually answers questions.
Thank you ROUTY
' Name: Hangman Game Project
' Purpose: Simulates the Hangman game
' Programmer:
Option Explicit On
Option Strict On
Option Infer Off
Public Class frmMain
Private Sub NewGameToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewGameToolStripMenuItem.Click
' simulates the Hangman game
Dim strWord As String
Dim strLetter As String
Dim blnValidWord As Boolean
Dim blnDashReplaced As Boolean
Dim blnGameOver As Boolean
Dim intIncorrect As Integer
Dim blnValidLetter As Boolean
'hide the picture boxes
picBottom.Visible = False
picPost.Visible = False
picTop.Visible = False
picRope.Visible = False
picHead.Visible = False
picBody.Visible = False
picRightArm.Visible = False
picLeftArm.Visible = False
picRightLeg.Visible = False
picLeftLeg.Visible = False
'get a 10-letter word from player 1 and convert to uppercase
strWord = InputBox("Enter a 10-letter word;", "Hangman Game").ToUpper
'determine whether the word contains 10 letters
blnValidWord = True 'assume the word is valid
If strWord.Length <> 10 Then
blnValidWord = False
Else
Dim intIndex As Integer
Do While intIndex < 10 AndAlso blnValidWord = True
If strWord.Substring(intIndex, 1) Like "[!A-Z]" Then
blnValidWord = False
End If
intIndex = intIndex + 1
Loop
End If
'if the world is not valid, display a message
If blnValidWord = False Then
MessageBox.Show("10 letters are required. ", "Hangman Game",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
'display ten dashes in lblWord and clear lblIncorrect
lblWord.Text = "----------"
lblIncorrect.Text = String.Empty
'get a letter from player 2 and convert to uppercase
strLetter = InputBox("Enter a letter:", "Letter", "", 600, 400).ToUpper
Dim intLetter As Integer
If strLetter.Substring(intLetter, 1) Like "[!A-Z]" Then
blnValidLetter = False
End If
End If
'if the world is not valid, display a message
If blnValidLetter = False Then
MessageBox.Show("Only letters of alphabet can be entered! ", "Hangman Game",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
'verify that player 2 entered a letter
' and that the games is not over
Else
End If
Do While strLetter <> String.Empty AndAlso
blnGameOver = False
'search the word for the letter
For intIndex As Integer = 0 To 9
'if the letter appears in the word, then
'replace the dash in lblWord and
'indicate that a replacement was made
If strWord.Substring(intIndex, 1) = strLetter Then
lblWord.Text = lblWord.Text.Remove(intIndex, 1)
lblWord.Text = lblWord.Text.Insert(intIndex, strLetter)
blnDashReplaced = True
End If
Next intIndex
' determine whether a dash was replaced
If blnDashReplaced = True Then
'if the word does not contain any dashes,
'the game is over because player 2
'guessed the word; otherwise, reset the
'blnDashReplaced variable for the next search
If lblWord.Text.Contains("-") = False Then
blnGameOver = True
MessageBox.Show("Great guessing!", "Game Over",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
blnDashReplaced = False
End If
Else
' processed when no dash was replaced
'display the incorrect letter, then update
'the intIncorrect variable,then show
'the appropriate picture box
lblIncorrect.Text =
lblIncorrect.Text & "" & strLetter
intIncorrect = intIncorrect + 1
Select Case intIncorrect
Case 1
picBottom.Visible = True
Case 2
picPost.Visible = True
Case 3
picTop.Visible = True
Case 4
picRope.Visible = True
Case 5
picHead.Visible = True
Case 6
picBody.Visible = True
Case 7
picRightArm.Visible = True
Case 8
picLeftArm.Visible = True
Case 9
picRightLeg.Visible = True
Case 10
picLeftLeg.Visible = True
blnGameOver = True
MessageBox.Show("Sorry, the word is " & strWord & ".", "Game Over",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Select
End If
'determine whetherr to get another letter
If blnGameOver = False Then
strLetter = InputBox("Enter a letter",
"Letter", "", 600, 400).ToUpper
End If
Loop
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
End Class
Routy