s080072 0 Newbie Poster

5x5 MATCHING WORDS AND IMAGE
Each time the user plays the game, the application should reshuffle a matching pair of ten words into the 5x5 Matrix. Include 5 pair of words and 5 pair of matching graphics.


New Game button should terminate the current game and clear everything on the game screen, clear the counter, reshuffle the words and present the player a completely new game.

Dim randomGenerator As New Random
Dim index1 As Integer
Dim index2 As Integer
Dim temp As String

For counter As Integer = 1 To 16
'generate two random numbers
index1 = randomGenerator.Next(0, 16)
index2 = randomGenerator.Next(0, 16)
'swap the two words
temp = wordListBox.Items(index1).ToString
wordListBox.Items(index1) = wordListBox.Items(index2)
wordListBox.Items(index2) = temp
Next counter

If selectionCounter = 16 Then
MessageBox.Show("Game Over.", _
"Concentration Game", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End If
End Sub


Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' fills the list box with 8 pairs of matching words,
' then calls a procedure to shuffle the words

wordListBox.Items.Add("Refrigerator")
wordListBox.Items.Add("Range")
wordListBox.Items.Add("Television")
wordListBox.Items.Add("Computer")
wordListBox.Items.Add("Washer/Dryer")
wordListBox.Items.Add("Dishwasher")
wordListBox.Items.Add("Car")
wordListBox.Items.Add("Trip")
wordListBox.Items.Add("Refrigerator")
wordListBox.Items.Add("Range")
wordListBox.Items.Add("Television")
wordListBox.Items.Add("Computer")
wordListBox.Items.Add("Washer/Dryer")
wordListBox.Items.Add("Dishwasher")
wordListBox.Items.Add("Car")
wordListBox.Items.Add("Trip")

Call ShuffleWords()


End Sub

Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub

Private Sub newButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles newButton.Click
' removes any words from the label controls, then
' enables the label controls, then resets the
' selection counter, and then calls a procedure
' to shuffle the words

Label1.Text = String.Empty
Label2.Text = String.Empty
Label3.Text = String.Empty
Label4.Text = String.Empty
Label5.Text = String.Empty
Label6.Text = String.Empty
Label7.Text = String.Empty
Label8.Text = String.Empty
Label9.Text = String.Empty
Label10.Text = String.Empty
Label11.Text = String.Empty
Label12.Text = String.Empty
Label13.Text = String.Empty
Label14.Text = String.Empty
Label15.Text = String.Empty
Label16.Text = String.Empty

Label1.Enabled = True
Label2.Enabled = True
Label3.Enabled = True
Label4.Enabled = True
Label5.Enabled = True
Label6.Enabled = True
Label7.Enabled = True
Label8.Enabled = True
Label9.Enabled = True
Label10.Enabled = True
Label11.Enabled = True
Label12.Enabled = True
Label13.Enabled = True
Label14.Enabled = True
Label15.Enabled = True
Label16.Enabled = True

selectionCounter = 0
Call ShuffleWords()


End Sub

Private Sub TestForMatch(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.Click, _
Label2.Click, Label3.Click, Label4.Click, Label5.Click, Label6.Click, Label7.Click, _
Label8.Click, Label9.Click, Label10.Click, Label11.Click, Label12.Click, Label13.Click, _
Label14.Click, Label15.Click, Label16.Click
'displays the appropriate words, and determines whether
'the user selected a matching pair of words

Dim labelNum As String
Dim index1 As Integer
Dim index2 As Integer

'update the selection counter
selectionCounter = selectionCounter + 1

'determine whether this is the first or second selection
If selectionCounter = 1 Then
'if this is the first label, extract the number from
'the label's name, then use the number to display the
'appropriate word from the list box
firstLabel = TryCast(sender, Label)
labelNum = firstLabel.Name.Substring(5)
index1 = Convert.ToInt32(labelNum) - 1
firstLabel.Text = wordListBox.Items(index1).ToString
Else
'this is the second label, so disable the game board
'then extract the number from the label's name, then
'use the number to display the appropriate word from
'the list box
boardTableLayoutPanel.Enabled = False
secondLabel = TryCast(sender, Label)
labelNum = secondLabel.Name.Substring(5)
index2 = Convert.ToInt32(labelNum) - 1
secondLabel.Text = wordListBox.Items(index2).ToString

'if both wors match, disable the corresponding
'label controls, then turn on the matchTimer;
'otherwise, turn on the noMatchTimer
If firstLabel.Text = secondLabel.Text Then
firstLabel.Enabled = False
secondLabel.Enabled = False
matchTimer.Enabled = True
Else
noMatchTimer.Enabled = True
End If


'reset the selection counter
selectionCounter = 0
End If

End Sub

Need help!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.