I've went back to my Bejeweled project and I'm currently stuck loading the gems. Right now I call:
Which is fine, but when the game starts there will be some that are in 3, 4, or 5 in a row. To try and prevent that I add:
However, whenever I run my program, I still get 3, 4, or 5 in a row. Could somebody shed some light for me?
Code:
'Nested Loop for each picturebox in the board array
For x As Integer = 0 To 5
For y As Integer = 0 To 7
'New instance of a picturebox
Dim pb As New PictureBox
'Set it's properties
With pb
.SizeMode = PictureBoxSizeMode.Zoom
.Size = New Size(50, 50)
.Location = New Point(x * 50, y * 50)
.Name = String.Format("BoardPiece{0}{1}", x, y)
Dim i As Integer = r.Next(0, 4)
.Image = rnd_image(i)
.Tag = i
End With
'Add it to the board array/panel
arr_board(x, y) = pb
pnl_board.Controls.Add(pb)
Next
NextCode:
'Check for matches and replace them
For x As Integer = 2 To 5
For y As Integer = 2 To 7
'If:
'x, y = x - 1, y
'x, y = x - 2, y
If arr_board(x, y).Tag.ToString = arr_board(x - 1, y).Tag.ToString AndAlso _
arr_board(x, y).Tag.ToString = arr_board(x - 2, y).Tag.ToString Then
'Get i
Dim i As Integer = CInt(arr_board(x, y).Tag)
'Loop until i is different
Do Until i <> CInt(arr_board(x, y).Tag)
i = r.Next(0, 4)
Console.WriteLine(i)
Loop
'Set a new image/tag
With arr_board(x, y)
.Image = rnd_image(i)
.Tag = i
End With
'If:
'x, y = x, y - 1
'x, y = x, y - 2
ElseIf arr_board(x, y).Tag.ToString = arr_board(x, y - 1).Tag.ToString AndAlso _
arr_board(x, y - 1).Tag.ToString = arr_board(x - 2, y).Tag.ToString Then
'Get i
Dim i As Integer = CInt(arr_board(x, y).Tag)
'Loop until i is different
Do Until i <> CInt(arr_board(x, y).Tag)
i = r.Next(0, 4)
Loop
'Set a new image/tag
With arr_board(x, y)
.Image = rnd_image(i)
.Tag = i
End With
End If
Next
Next