# Thread: I need help with this memory game

1. ## I need help with this memory game

I'm currently doing with this memory game and i have a problem on how to make it using C languae. Please help me on how to implement it. I used colors that will serves as the hidden image inside the tile ( it is 4 x 7) and I had a trouble with it. It is our project for this semester. Please I need your help with this project.

My implementation in setting the colors:

int boxcolor[4][7];

void setcolor();
int exist[14]={0}, okey=0,i,j;
randomize();
for(i=0;i<4;i++)
for(j=0;j<7;j++){
do{
boxcolor[i][j]=random(13)+1;
if(exist[boxcolor[i][j]-1] > 1) okey=1;
else{
exist[boxcolor[i][j]-1]++;
okey=0;
}
}while(okey==0);
}
}

And i have also a problem on how to track the rest of the boxes that has been revealed and the rest of the functions. Please you help is much appreciated.

2. Assign the colors in pairs. This way you're sure each card/square will have a matching card/square. You may want something like:
Code:
```/**
*** TS = total squares
*** x = counter for total number of squares being used
*** y = counter for square color being placed
*** MC = max colors
*** color = current color
*** s = spot to place color
*** fs = free spot
*** uc = used count
**/

for( x = 0; x < TS; )
{
color = (rand()%MC)+1;
for(y=0;y<2;y++,x++)
{
/** Place 1 color. **/
s = rand()%(TS-x);
for( fs=0, uc=0; fs+uc < TS; )
{
if( squares[fs+uc] == 0 )
{ if( fs==s )
{ squares[fs+uc] = color; break; }
else
fs++;
}
else
uc++;
}
}
}```
Ain't that puuuurrdy?

Quzah.

3. Thanks! but can a variable be used without having to declare it? i'm a little bit confused with the line:

if( squares[fs+uc] == 0 )
//squares is not declared.

and also in memory game the colors must be in random everytime it will runs. Thanks for this, but can you explain it clearer the line:

color = (rand()%MC)+1; and s = rand()%(TS-x); Thanks!

Another is that, how can I trace the status of the square, weither it is currently open or not and back again if it is not the pair of the opened one.