views:

973

answers:

3

Hi!

I'm developing a puzzle game for windows mobile. The objetive is to split an image in nine parts and rearrage them to obtain the original image. These split images are put on pictureBoxes and these pictureBoxes are redistributed in a matrix of 3X3 cells.

The user move this cells to arrange them in the correct position (it's a puzzle game!).

I need something to access these pictureBoxes and to know where are they in the matrix. Suppose that I need to update the image on row 1, column 2 (it's only an example).

In C++ I use pointers to reference object, but I don't know how to do it with C#.

Any advice?

Thanks!

+1  A: 
//This is a reference object
MyCustomObject o1 = new MyCustomObject(imageUrl, row, col);

So from my example I am creating a custom object which holds the url of the image and also a row and column reference.

I can then call:

int row = o1.Row;
int col = o1.Col;
string imageUrl = o1.ImageUrl;

You can then use how you wish.

Hope this helps:

Andrew

REA_ANDREW
+1  A: 

One possible way to do this is to build a puzzle peice class which would hold a reference to the image, it's current position and it's target position.

public class PuzzlePeice

{
public Bitmap Image {get; }
puliic Point Position {get; set; }
public Point TargetPosition {get; };


}

then assuming peice is an instance of the above class, moving a peice would look like this:

peice.Postion = new Point(x,y);

TargetPosition indicates where the peice should be within the matrix for it to form the correct image, this value would of course come from whatever data source you get puzzle info fron and could be set in the constructor

Hope this helps

Crippledsmurf
+2  A: 

Just create the matrix with objects that contain the reference to the PictureBox.

MyObject[,] layout = new MyObject[3,3];

public class MyObject
{
        #region attributes        
        private PictureBox pictureBox;
        #endregion

        public MyObject(PictureBox pictureBox)
        {
            this.pictureBox = pictureBox;
        }
}
João Augusto
I'm going to use this. I can do this:The user move pictureBox on cell 2,2 to cell 1,2. What it's better?SOLUTION a)PictureBox aux = objectB.pictureBox;objectB.pictureBox = objectA.pictureBox;objectA.pictureBox = aux;SOLUTION BMyObject aux = objectB;objectB = objectA;objectA=aux;Or inter
VansFannel