daweefolk
November 4th, 2009, 06:23 AM
I'm trying to make a minesweeper type game and I'm stuck at getting the squares to communicate with each other (so they know how many mines are nearby). Each square is in a class i made, and they have the variables sq_X (its x location on the "map"), sq_Y (its y location), sq_HasMine (does this square have a mine on it?), sq_Id (number, 1-100, of the square. 1 is at 1,1 and 100 is at 10,10), an array sq_AdjacentSquares (stores the sq_Ids of the adjacent squares), and sq_MinesNearby (how many mines are adjacent to this square?).
I think I need to get the squares to "contact" the ones that are one x and or y away. However, I don't know how to refer to them. I'm kinda a newbie at c++, and especially to oop.
when I create the squares in my program, I call them "square1" to "square100", and assign their sq_Id to their name's number.
How can I retrieve the sq_Id from one of the objects without referring to them by name?
Short version:How can I access an object's variable without calling the object by name? is this even possible?
I think I need to get the squares to "contact" the ones that are one x and or y away. However, I don't know how to refer to them. I'm kinda a newbie at c++, and especially to oop.
when I create the squares in my program, I call them "square1" to "square100", and assign their sq_Id to their name's number.
How can I retrieve the sq_Id from one of the objects without referring to them by name?
Short version:How can I access an object's variable without calling the object by name? is this even possible?