would some one please help me with this?? i 've got an assigment from my professor which is in a University level (p.s i am still in college, and this class suppose to be the"introduction of programmng") However, in the game we suppose to create a "BlackOut Game", which we have to assign nine game buttons at runtime but not at design-time. I was able to figure out how to display the nine buttons at the runtime, but i could not figure out how to randomize the nine button. i tried to create a random generator(rndGenerator) in the program but i have no idea how to use it so i can randomize all the buttons. could someone give me some ideas?
Public Class Form1
Const ROWSIZE As Integer = 5
Const COLSIZE As Integer = 5
Dim gameButtons(,) As Button = New Button(ROWSIZE, COLSIZE) {}
Dim mintMoves As Integer = 0
Dim rndGenerator As New Random(System.DateTime.Now.Millisecond)
Dim myRnd As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim row As Integer
Dim col As Integer
Dim btnWidth As Integer = 70
Dim btnHeight As Integer = 70
'instantiate all the array buttons
For row = 0 To ROWSIZE - 1
For col = 0 To COLSIZE - 1
gameButtons(col, row) = New Button()
'use the Addhandler keyboard to book an event handler
'to an event for each array button
AddHandler gameButtons(col, row).Click, AddressOf ClickHandler
If row >= 1 And row <= 3 And col >= 1 And col <= 3 Then
Me.Controls.Add(gameButtons(col, row))
gameButtons(col, row).Size() = New Size(New Point(btnWidth, btnHeight))
gameButtons(col, row).Location() = New Point((col - 0.8) * btnWidth, (row - 0.8) * btnHeight)
gameButtons(col, row).Name = "btn" + Convert.ToString(col) + "_" + Convert.ToString(row)
gameButtons(col, row).Text = "btn" + Convert.ToString(col) + "_" + Convert.ToString(row)
gameButtons(col, row).BackColor() = Color.Red
End If
Next
Next
End Sub
Public Sub ClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Dim row As Integer
Dim col As Integer
Dim str As String
str = sender.Name
row = str.Substring(3, 1)
col = str.Substring(5, 1)
swapColor(gameButtons(row, col)) 'swap the color of the button
swapColor(gameButtons(row + 1, col)) 'swap the color above
swapColor(gameButtons(row - 1, col)) 'swap the color below
swapColor(gameButtons(row, col + 1)) 'swap the color to the right
swapColor(gameButtons(row, col - 1)) 'swap the color to the left
End Sub
Private Sub swapColor(ByRef button1 As Button)
If button1.BackColor = Color.Red Then
button1.BackColor = Color.White
Else
button1.BackColor = Color.Red
End If
End Sub
End Class