Array of Picture boxes

225 Views Asked by At

So i'm doing a board game and the only idea that came to mind was to make the board with picture boxes. My board is 26 per 32 squares which means that i need alot of picture boxes to do this.

I thought of two methods and i'm not sure if they work.

One would be to actually put the 832 pictures boxes on my form and then run through them and populate the array however this would make the form really messy and laggy to make. I wrote a bit of code by hand on this, don't know if it would work but it's just to have an idea:

    For i = 831 To 0 Step -1
        PictureBox.i
        For e = arrMap(0, 0) To arrMap(25, 31)
            arrMap(a, e) = PictureBox.i
            If e = 32 Then
                e = 0
                a = a + 1
            End If
        Next
    Next

The other method that i thought of was to put one picture box in the right place and then create another next to it and put it into the array on the next index location, when the a row is completed i would then put another one on top of the starting point and continue like that until all the picture boxes are create and in the Array.

I think i need the array because i need to compare position on the game pieces and the array i think it's the best way to do so.

Is there a better way to make the board for the game or if this is viable any ideas?

PS. I'm doing this is VB

1

There are 1 best solutions below

1
On

It is not good idea to use separated Pictue Box for each state,

I suggest use Panel with height and width of game board and set background image as board (map of matrix)

Separate panel as matrix and find clicked matrix index position by mouse click position

For example 80 to 90 board .

if each matrix index is 5*5 pixel image then 80*5 and 90*5 is height and width of panel

Finding clicked position on Panel mouse click >> For example Position (21,14) => [21/5] = 4 and [14/5] = 2 therefore matrix [4,2] is selected

Now use current background image and draw new image or change image with new one

If there is only one moving image you can use one picture box and move the picture box by this algorithm

Using draw graphic command instead of new Pictue Box to change background image to new image with new state

You cans save matrix data and game data in custom class like game data

By the way it is not good idea to use image box for this type of games :)