Classic memory game board (size 4 * 5)
Hi! I've made a program where the user inputs a row and a column for two cards turned down. If the cards are the same number, it's a match. Don't misunderstand me, according to the first sentence. It should work like the classic game Memory.
Example run:
----0 1 2 3 4
--|-------------
0 | * * * * *
1 | * * * * *
2 | * * * * *
3 | * * * * *
First card (row, col): 0 0
Second card (row, col): 1 0
Match!
----0 1 2 3 4
--|-------------
0 | 6 * * * *
1 | 6 * * * *
2 | * * * * *
3 | * * * * *
I have fixed so that I get the correct index for the card in a shuffled array. But I also need to print that card in a different function. In this function I don't know how to reach these variables since they're in the main block (Without using Object Oriented Programming).
main
A piece of code of the main-block
Code:
printf("\nFirst card (row, col): ");
scanf("%d %d", &cardRow1, &cardCol1);
printf("\nSecond card (row, col): ");
scanf("%d %d", &cardRow2, &cardCol2);
int getCard1, getCard2;
getCard1 = gameBoard[setCardIndex(cardRow1, cardCol1)]; // cardRow1*COLS + cardCol1
getCard2 = gameBoard[setCardIndex(cardRow2, cardCol2)]; // cardRow2*COLS + cardCol2
Code:
int prtCards(int arr[], int taken[], int sizeOfArr) {
printf("\n\n 0 1 2 3 4");
printf("\n--|--------------");
int i, rows = 0;
int j = 0;
for (i = 0; i < ROWS; i++) {
if (taken[i] == 0)
printf("\n%d | * ", rows);
else
printf("\n%d | %d ", rows, arr[i*COLS + j]);
for (j = 0; j < ROWS; j++) {
if (taken[i] == 0)
printf(" * ");
else
printf(" %d ", arr[i*COLS + j]); // i*COLS+j
}
rows++;
}
}
taken[] - if a pair of cards have been found set taken[i] = 1
printf("\n%d | %d ", rows, arr[i*COLS + j]);
should be something like this
printf("\n%d | %d ", rows, arr[userRow*COLS + userCol]);