passing variables
-
I 2 global variables:
bool PrintBoard[5][5];
bool MemoryBoard[5][5];Then I have a function:
void DoMove(int x,int y)
{
x--;
y--;PrintBoard\[x\]\[y\] = !PrintBoard\[x\]\[y\]; if (y > 0) {//up PrintBoard\[x\]\[y - 1\] = !PrintBoard\[x\]\[y - 1\]; } if (y < 4) {//dow PrintBoard\[x\]\[y + 1\] = !PrintBoard\[x\]\[y + 1\]; } if (x > 0) {//left PrintBoard\[x - 1\]\[y\] = !PrintBoard\[x - 1\]\[y\]; } if (x < 4) {//right PrintBoard\[x + 1\]\[y\] = !PrintBoard\[x + 1\]\[y\]; } return;
}
As you can see, the DoMove function only changes PrintBoard. I would like it to be able to change either variable with out much more code (I don't see the point of re-using code here). I was thinking I could do something like adding another argument to the function that I could pass the global to it, but I couldn't figure out how. Any Ideas? Thanks
-
I 2 global variables:
bool PrintBoard[5][5];
bool MemoryBoard[5][5];Then I have a function:
void DoMove(int x,int y)
{
x--;
y--;PrintBoard\[x\]\[y\] = !PrintBoard\[x\]\[y\]; if (y > 0) {//up PrintBoard\[x\]\[y - 1\] = !PrintBoard\[x\]\[y - 1\]; } if (y < 4) {//dow PrintBoard\[x\]\[y + 1\] = !PrintBoard\[x\]\[y + 1\]; } if (x > 0) {//left PrintBoard\[x - 1\]\[y\] = !PrintBoard\[x - 1\]\[y\]; } if (x < 4) {//right PrintBoard\[x + 1\]\[y\] = !PrintBoard\[x + 1\]\[y\]; } return;
}
As you can see, the DoMove function only changes PrintBoard. I would like it to be able to change either variable with out much more code (I don't see the point of re-using code here). I was thinking I could do something like adding another argument to the function that I could pass the global to it, but I couldn't figure out how. Any Ideas? Thanks
void DoMove(bool Array[][5], int x, int y)
{
x--;
y--;
Array[x][y] = !Array[x][y];
...
}...
DoMove(PrintBoard, 2, 3);
DoMove(MemoryBoard, 3, 4);
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
void DoMove(bool Array[][5], int x, int y)
{
x--;
y--;
Array[x][y] = !Array[x][y];
...
}...
DoMove(PrintBoard, 2, 3);
DoMove(MemoryBoard, 3, 4);
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
Thank you.