dimanche 25 octobre 2015

Generate grid so that there are approximately the same amount of colors

I am writing a little game (Bejeweled) in Visual Basic, for which I need to randomly generate a grid with labels and colors for those labels (as seen on this image).

This isn't a problem, but I want to generate the grid so that there are approximately the same amount of labels for each color. I've already searched the internet, but haven't found any solution for this problem.

I automatically generate a grid with labels, after which I'm using this code to generate a random color and give that color to those predefined labels, called lbl_i_j (with i and j being the row and column the label is in):

Dim random As Random = New Random
Dim color As Integer = random.next(0, 6)

Select Case color
    Case 0
        lbl_i_j.BackColor = Color.Green
    Case 1
        lbl_i_j.BackColor = Color.Yellow
    Case 2
        lbl_i_j.BackColor = Color.Orange
    Case 3
        lbl_i_j.BackColor = Color.Red
    Case 4
        lbl_i_j.BackColor = Color.Blue
    Case 5
        lbl_i_j.BackColor = Color.Purple

In essence I want to generate a heap of numbers in a certain interval, but I want there to be approximately the same amount of each number.

I was thinking there was a special argument for this purpose, but to be frank, I don't have a clue. Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire