Solved

Re-populate board after all buttons have been selected.

Posted on 2008-10-15
2
218 Views
Last Modified: 2012-05-05
I've created a Jeopardy style game. What I need to do is re-populate the board of buttons with new questions once all the questions have been answered. When a button has been selected, the text is changed to " ". I've created a function to check if the round should be over but how can I check to see if the botton text is blank after each button is selected and have it load the new board if it is?
~Mike

Friend Function RoundIsOver() As Boolean
        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is Button AndAlso ctrl.Text <> " " Then
                Return False
            End If
        Next
        Return True
        bround1 = False
    End Function
 
Private Sub frmBoard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim oBoard As New ClsBoard
        Dim dtCategories As New DataTable
 
        If bRoundOver = True Then
            bround1 = True
            'hook up array
            'ROUND 1
            arrCol1(0) = btn1200
            arrCol1(1) = btn1400
            arrCol1(2) = btn1600
            arrCol1(3) = btn1800
            arrCol1(4) = btn11000
 
            arrCol2(0) = btn2200
            arrCol2(1) = btn2400
            arrCol2(2) = btn2600
            arrCol2(3) = btn2800
            arrCol2(4) = btn21000
 
            arrCol3(0) = btn3200
            arrCol3(1) = btn3400
            arrCol3(2) = btn3600
            arrCol3(3) = btn3800
            arrCol3(4) = btn31000
 
            arrCol4(0) = btn4200
            arrCol4(1) = btn4400
            arrCol4(2) = btn4600
            arrCol4(3) = btn4800
            arrCol4(4) = btn41000
 
            arrCol5(0) = btn5200
            arrCol5(1) = btn5400
            arrCol5(2) = btn5600
            arrCol5(3) = btn5800
            arrCol5(4) = btn51000
 
            arrCol6(0) = btn6200
            arrCol6(1) = btn6400
            arrCol6(2) = btn6600
            arrCol6(3) = btn6800
            arrCol6(4) = btn61000
 
            dtCategories = oBoard.GetCategories
 
            txtCat1.Text = dtCategories.Rows(0).Item(1)
            txtCat2.Text = dtCategories.Rows(1).Item(1)
            txtCat3.Text = dtCategories.Rows(2).Item(1)
            txtCat4.Text = dtCategories.Rows(3).Item(1)
            txtCat5.Text = dtCategories.Rows(4).Item(1)
            txtCat6.Text = dtCategories.Rows(5).Item(1)
 
            For x = 0 To 5
                oBoard.Used(dtCategories.Rows(x).Item(0))
            Next
            For x = 0 To 4
                arrCol1(x).Text = ("$" & (x + 1) * 200)
                arrCol2(x).Text = ("$" & (x + 1) * 200)
                arrCol3(x).Text = ("$" & (x + 1) * 200)
                arrCol4(x).Text = ("$" & (x + 1) * 200)
                arrCol5(x).Text = ("$" & (x + 1) * 200)
                arrCol6(x).Text = ("$" & (x + 1) * 200)
                My.Computer.Audio.Play("BoardFill.wav")
 
            Next
            m_Categories = dtCategories
            Me.Show()
        Else
            'ROUND 2
            arrCol1(0) = btn1200
            arrCol1(1) = btn1400
            arrCol1(2) = btn1600
            arrCol1(3) = btn1800
            arrCol1(4) = btn11000
 
            arrCol2(0) = btn2200
            arrCol2(1) = btn2400
            arrCol2(2) = btn2600
            arrCol2(3) = btn2800
            arrCol2(4) = btn21000
 
            arrCol3(0) = btn3200
            arrCol3(1) = btn3400
            arrCol3(2) = btn3600
            arrCol3(3) = btn3800
            arrCol3(4) = btn31000
 
            arrCol4(0) = btn4200
            arrCol4(1) = btn4400
            arrCol4(2) = btn4600
            arrCol4(3) = btn4800
            arrCol4(4) = btn41000
 
            arrCol5(0) = btn5200
            arrCol5(1) = btn5400
            arrCol5(2) = btn5600
            arrCol5(3) = btn5800
            arrCol5(4) = btn51000
 
            arrCol6(0) = btn6200
            arrCol6(1) = btn6400
            arrCol6(2) = btn6600
            arrCol6(3) = btn6800
            arrCol6(4) = btn61000
 
            dtCategories = oBoard.GetCategories
 
            txtCat1.Text = dtCategories.Rows(0).Item(1)
            txtCat2.Text = dtCategories.Rows(1).Item(1)
            txtCat3.Text = dtCategories.Rows(2).Item(1)
            txtCat4.Text = dtCategories.Rows(3).Item(1)
            txtCat5.Text = dtCategories.Rows(4).Item(1)
            txtCat6.Text = dtCategories.Rows(5).Item(1)
 
            For x = 0 To 5
                oBoard.Used(dtCategories.Rows(x).Item(0))
            Next
            For x = 0 To 4
                arrCol1(x).Text = ("$" & (x + 1) * 400)
                arrCol2(x).Text = ("$" & (x + 1) * 400)
                arrCol3(x).Text = ("$" & (x + 1) * 400)
                arrCol4(x).Text = ("$" & (x + 1) * 400)
                arrCol5(x).Text = ("$" & (x + 1) * 400)
                arrCol6(x).Text = ("$" & (x + 1) * 400)
                My.Computer.Audio.Play("BoardFill.wav")
            Next
            m_Categories = dtCategories
            Me.Show()
        End If
    End Sub
 
Private Sub btnCol1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1200.Click, btn1400.Click, btn1600.Click, btn1800.Click, btn11000.Click
 
        m_sender = Strings.Right(sender.tag, 1)
        icolumn = Strings.Left(sender.tag, 1) - 1
        irow = Strings.Right(sender.tag, 1) - 1
 
        If bround1 = True Then
            temp = (m_sender * 200)
        Else
            temp = (m_sender * 400)
        End If
 
        'hook up array
        Dim frmQ As New frmQuestion
        vwQuestion.RowFilter = "CategoryID = '" & CStr(m_Categories.Rows(icolumn).Item("CategoryID")).Replace("'", "\'") & "'"
        frmQ.Question = vwQuestion.ToTable.Rows(irow).Item(2)
        frmQ.Answer1 = vwQuestion.ToTable.Rows(irow).Item(3)
        frmQ.Answer2 = vwQuestion.ToTable.Rows(irow).Item(4)
        frmQ.Answer3 = vwQuestion.ToTable.Rows(irow).Item(5)
        frmQ.Answer4 = vwQuestion.ToTable.Rows(irow).Item(6)
        frmQ.CorrectAnswer = vwQuestion.ToTable.Rows(irow).Item(7)
 
        Dim btn As Button = DirectCast(sender, Button)
        btn.Text = ""
        btn.Enabled = False
 
 
        iResult = frmQ.ShowDialog()
        If iResult = 1 Then
            Score = Score + temp
        Else
            Score = Score - temp
        End If
        lblScore.Text = Score
    End Sub

Open in new window

0
Comment
Question by:98fatboyrider
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 22728386
At the bottom of you btnCol1_click() method, check for an end of game situation.

Not sure how you are loading a new board...do you want the Load() code to run again?

    Private Sub btnCol1_click(...) Handles ...

        ...

        iResult = frmQ.ShowDialog()
        If iResult = 1 Then
            Score = Score + temp
        Else
            Score = Score - temp
        End If
        lblScore.Text = Score

        If RoundIsOver() Then
            ' ...load a new board...
            frmBoard_Load(Nothing, Nothing)
        End If

    End Sub
0
 

Author Closing Comment

by:98fatboyrider
ID: 31506610
That worked, thank you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question