zareck 0 Newbie Poster

Hi I am new to the forums and have problems with a program I am trying to write. If you could point me in the right direction. It is a vb.net version of the concentration game with a twist. Upon form_load a listbox is loaded with 8 item names(2 of each for total of 16) what I am required to do before anyone plays the game is to find one particular item and its duplicate and replace them using WILDCARD with another item from the listbox which could results in four of one or a pair that don't match. I figured my changes should happen prior to the suffle that occurs prior to game start. ANy idea's would help! Here is my code;

Public Class MainForm

    Private firstLabel As Label
    Private secondLabel As Label
    Private selectionCounter As Integer


    Private Sub ShuffleWords()
        'shuffles the words in the list box
        Dim listBoxIndex1 As Integer
        Dim listBoxIndex2 As Integer
        Dim input As String
        Dim output As String
        Dim gText As String
        Dim gText2 As String
        ' find the variables

        wordListBox.SelectedIndex = wordListBox.FindStringExact("Washer/Dryer")
        gText = wordListBox.Text
        listBoxIndex1 = wordListBox.SelectedIndex
        ' Display the message box
        MsgBox(gText & ", item number " & CStr(listBoxIndex1) & " is currently selected. ")
        wordListBox.SelectedIndex = wordListBox.FindStringExact("Washer/Dryer")
        gText2 = wordListBox.Text
        listBoxIndex2 = wordListBox.SelectedIndex
        ' Display the message box
        MsgBox(gText2 & ", item number " & CStr(listBoxIndex2) & " is currently selected. ")



        Dim randomGenerator As New Random
        Dim index1 As Integer
        Dim index2 As Integer
        Dim temp As String = String.Empty

        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



    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 


        Dim labelNum As String = String.Empty
        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)
            Integer.TryParse(labelNum, index1)
            index1 = index1 - 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 and 
            'use the number to display the appropriate word form
            'the list box
            boardTableLayoutPanel.Enabled = False
            secondLabel = TryCast(sender, Label)
            labelNum = secondLabel.Name.Substring(5)
            Integer.TryParse(labelNum, index2)
            index2 = index2 - 1
            secondLabel.Text = wordListBox.Items(index2).ToString

            'if both words 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



    Private Sub matchTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles matchTimer.Tick
        ' when the two words match, the game board is enabled
        ' and the timer is turned off

        boardTableLayoutPanel.Enabled = True
        matchTimer.Enabled = False

    End Sub

    Private Sub noMatchTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles noMatchTimer.Tick
        ' when the words do not match, the words are
        ' removed from the labels, the game board is enabled,
        ' and the timer is turned off

        firstLabel.Text = String.Empty
        secondLabel.Text = String.Empty
        boardTableLayoutPanel.Enabled = True
        noMatchTimer.Enabled = False
    End Sub
End Class