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

i am sorry...maybe i didn't not explain my problems very well....so from the diagram below its the diagram for what i created on the vb6 fom1 under the Private form1_load . All of them are at runtime.

 0      1      2       3        4
       l       l        l        l
  ----l------l------l------l------
1     l 1 - 1l 2 - 1l 3 - 1l------
  ----l------l------l------l-----
2     l 1 - 2l 2- 2 l 3- 2 l-----
  ----l------l------l------l-----
3     l 1- 3 l 2 - 3l 3 - 3l-----
 -----l------l------l------l-----
4     l        l        l       l

so the game is basically called "Blackout game"
.In the game when player press a button , then the button that is pressed,and the buttons next to them will swap color. For example, if i all of them have the same BackColor.Red then when i press the button(3-1) then button (3-1), (2-1), and (3-2) swap their backColor to white. And if at the same time i press the button (2-2) then it will result in color swaps on button(2-2)=white , (2-1)=Red ,and (3-2)=Red. Vice versa.

However, i created the statement "Dim rndGenerator As New Random (System. Datetime.Now.Millisecond)" I only know how to swap Integers like below:

Dim rndNum1 As Integer
Dim rndNum2 As Integer
Dim rndGenerator As new Random(System.Datetime.Now.Millisecond)

rndNum1 = rndGenerator .Next (1, 11)
rndNum2 = rndGenerator . Next (1, 11)
Dim temp as Integer

temp = rndNum1
rndNum1 = rndNum2
rndNum2 = temp

If i want to use this statement in the game i am doing right now, then how should i change it so i can randomize all the BackColors?? Someone please give me some hint~"~

I am sorry...maybe i didn't not explain my problems very well....so from the diagram below its the diagram for what i created on the vb6 fom1 under the Private form1_load . All of them are at runtime.

  0--l--(1)-l--(2)-l--(3)-l--(4)
(0)--l       
  ----l------l------l------l------
(1)--l 1 - 1l 2 - 1l 3 - 1l------
  ----l------l------l------l-----
(2)--l 1 - 2l 2- 2 l 3- 2 l-----
  ----l------l------l------l-----
(3)--l 1- 3 l 2 - 3l 3 - 3l-----
 -----l------l------l------l-----
(4)--l

so the game is basically called "Blackout game"
.In the game when player press a button , then the button that is pressed,and the buttons next to them will swap color. For example, if i all of them have the same BackColor.Red then when i press the button(3-1) then button (3-1), (2-1), and (3-2) swap their backColor to white. And if at the same time i press the button (2-2) then it will result in color swaps on button(2-2)=white , (2-1)=Red ,and (3-2)=Red. Vice versa.

However, i created the statement "Dim rndGenerator As New Random (System. Datetime.Now.Millisecond)" I only know how to swap Integers like below:

Dim rndNum1 As Integer
Dim rndNum2 As Integer
Dim rndGenerator As new Random(System.Datetime.Now.Millisecond)

rndNum1 = rndGenerator .Next (1, 11)
rndNum2 = rndGenerator . Next (1, 11)
Dim temp as Integer

temp = rndNum1
rndNum1 = rndNum2
rndNum2 = temp

If i want to use this statement in the game i am doing right now, then how should i change it so i can randomize all the BackColors?? Someone please give me some hint~"~ sorry to waste the space of replying but #2's diagram is not clear ....hope someone could undersatnd this one..AND IF YOU CAN'T UNDERSTAND I WOULD TRY MY BEST TO EXPLAIN IT TO YOU...SO PLEASE SOMEONE HELP ME!!

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.