Info

Size Mode

Stretch

All of the code required to build the Hangman program is seen next.

Option Compare Database Option Explicit

' Form level variables to track game results.

Dim iCounter As Integer

Dim letterl As String

Dim letter2 As String

Dim letter3 As String

Dim letter4 As String

Dim letter5 As String

Dim letter6 As String

Private Sub cmdStart_Click() MsgBox "A five letter word

'Reset the game board iCounter = 0

for database.", , "Hangman"

Me.cmdVerify.Enabled = True

Me.imgHead.Visible = False Me.imgBody.Visible = False Me.imgLeftArm.Visible = False Me.imgRightArm.Visible = False Me.imgLeftLeg.Visible = False Me.imgRightLeg.Visible = False

Me.txtA.Enabled = True

Me.txtB.Enabled = True

Me.txtC.Enabled = True

Me.txtD.Enabled = True

Me.txtE.Enabled = True

Me.txtF.Enabled = True

Me.txtA.Value =

Me.txtB.Value =

Me.txtC.Value =

Me.txtD.Value =

Me.txtE.Value =

Me.txtF.Value = End Sub

Private Sub cmdVerify_Click()

If (Me.txtA.Value & Me.txtB.Value & Me.txtC.Value & Me.txtD.Value & Me.txtE.Value & Me.txtF.Value) = "Access" Then

MsgBox "You won!", , "Hangman" Me.cmdStart.SetFocus Me.cmdVerify.Enabled = False

Else

' User did not guess the correct letter. ' Find an available body part to display. If Me.imgLeftLeg.Visible = False Then Me.imgLeftLeg.Visible = True iCounter = iCounter + 1 Elself Me.imgRightLeg.Visible = False Then Me.imgRightLeg.Visible = True iCounter = iCounter + 1 Elself Me.imgBody.Visible = False Then Me.imgBody.Visible = True iCounter = iCounter + 1 Elself Me.imgLeftArm.Visible = False Then Me.imgLeftArm.Visible = True iCounter = iCounter + 1 Elself Me.imgRightArm.Visible = False Then Me.imgRightArm.Visible = True iCounter = iCounter + 1

Elself Me.imgHead.Visible = False Then Me.imgHead.Visible = True iCounter = iCounter + 1 End If

' Find out if the user has lost. If iCounter = 6 Then

MsgBox "Sorry, you lost.", , "Hangman" Me.txtA.Enabled = False Me.txtB.Enabled = False Me.txtC.Enabled = False Me.txtD.Enabled = False Me.txtE.Enabled = False Me.txtF.Enabled = False Else

MsgBox "You have " & 6 - iCounter & _ " chances left!", , "Hangman" End If

End If End Sub

Private Sub Form_Load()

' Start the game by calling an event procedure cmdStart_Click

End Sub

Private Sub txtA_LostFocus() ' Ensure correct case If Me.txtA.Value = "a" Then

Me.txtA.Value = "A" End If End Sub

Private Sub txtB_LostFocus() ' Ensure correct case If Me.txtB.Value = "C" Then

Me.txtB.Value = "c" End If End Sub

Private Sub txtC_LostFocus() ' Ensure correct case If Me.txtC.Value = "C" Then

Me.txtC.Value = "c" End If End Sub

Private Sub txtD_LostFocus() ' Ensure correct case If Me.txtD.Value = "E" Then

Me.txtD.Value = "e" End If End Sub

Private Sub txtE_LostFocus() ' Ensure correct case If Me.txtE.Value = "S" Then

Me.txtE.Value = "s" End If End Sub

Private Sub txtF_LostFocus() ' Ensure correct case If Me.txtF.Value = "S" Then

Me.txtF.Value = "s" End If End Sub

Private Sub cmdQuit_Click()

DoCmd.Quit End Sub

0 0

Post a comment