-1

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

3
  • Seems like the obvious option is to use a TableLayoutPanel and add a PictureBox to each cell. Not sure if there would be performance issues but that's the first thing I would try. Commented Dec 18, 2016 at 12:15
  • PictureBox only exists for point-and-click convenience. But sure, it makes a simple Graphics.DrawImage() call a fat 3 orders of magnitude more expensive. Label is another one that's excessive, the slow way to call TextRenderer.DrawText(). So just don't use it. Commented Dec 18, 2016 at 13:06
  • My game would be based to point a character of one picture box and then move it to another which would be just point and click
    – Zamura
    Commented Dec 18, 2016 at 14:09

1 Answer 1

0

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 :)

1
  • I will try to implement this, i'll get back with results :) thanks
    – Zamura
    Commented Dec 18, 2016 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.