The Memory Game...HELP!!

In my CompSci class we are supposed to create the memory game where one would layout cards, in our case in a 4x4, and then flip over all the cards by getting a match. So flip one card and then another. If they are the same they stay faced up, if they are different you flip them back over.

Here is the code that I have so far listed below. I am just confused on what a bool function is. I know that I need it to have all the cards facing down, by means of a star or *, and then when the number is choosen by coordinates then display that number.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Use a char array for the bool for when face up and have that connect to the int array if choosen correctly


#include<iostream>
#include<fstream>
using namespace std;


void Shuffler (int garray[][10], int option);
void DisplayBoard( int garray[][10], bool isFaceUp[][10], int option);

// These functions may or may not be used after editing
void Print2DArray(int arr1[][10], int r, int c);
int Fill_array( int array1[][10], int no_rows, int no_cols);


const int SIZE = 4;


int main ()
{
	int rows, cols, max, option, X1, Y1,X2, Y2, GameArray[SIZE][SIZE];
	bool isFaceUp[SIZE][SIZE];	// declaration for the number of rows and columns and the array size of 20 rows and 15 columns as a max
	
	for(int i = 0; i < SIZE; i++)			//set all values of isFaceUp to false so all cards are face down
	{
		for(int a = 0; a <SIZE; a++)
		{
			isFaceUp[i][a] = false;
		}
	}

	cout << "Please enter the type of game you would like to play by choosing either a 2, 4, 6, 8 or 10." << endl;
	cin >> option; 

	while ( (option != 2) || (option != 4) || (option != 6) || (option != 8) || (option != 10) )
	{
		cout << "You have entered an invalid number. Please try again." << endl;
		cin >> option;
	}

	Shuffler ( GameArray, option);		// Shuffle the values in the array

	// Show the table to the player

	cout << "Please indicate the first card you would like to flip over by entering the X and Y coordinate." << endl;
	cout << "Enter the X coordinate." << endl;
	cin >> X1; 
	cout << "Enter the Y coordinate." << endl;
	cin >> Y1;
	
	cout << "Please indicate the second card you would like to flip over by entering the X and Y coordinate." << endl;
	cout << "Enter the X coordinate." << endl;
	cin >> X1; 
	cout << "Enter the Y coordinate." << endl;
	cin >> Y1;

	DisplayBoard(GameArray, isFaceUp, option);


												// input the number of columns
	//call function to fill array
	Fill_array( GameArray, option, option);
	//call function to print array
	cout << "Below is the given values for your array." << endl;
	Print2DArray( GameArray, rows, cols);
	
        
}

// functions found below

void Shuffler (int garray [][SIZE], int option)
{
	int a = 1;
	for (int i = 0; i < option; i++)
	{
		if(i == option/2)
			a = 0;
		for(int r = 0; r < option; r++)
		{			
			garray[i][r] = a;
			a++;
		}
	}

	for(int i = 0; i < option; i++)
	{
		int a, b, c, d, e;
		a = rand()% option;
		b = rand() % option;
		c = rand()% option;
		d = rand() % option;

		e = garray[a][b];
		garray[a][b] = garray[c][d];
		garray[c][d] = e;
	}
}

void DisplayBoard( int garray[][SIZE], bool isFaceUp[][SIZE], int option)
{
	const int ARRAY_SIZE = option;
	const int NUMS_USED = option * 2;
	int array[SIZE][SIZE];
	bool arrayBool[SIZE][SIZE];
	bool arrayAvail[SIZE][SIZE];

	for (int j = 0; j < option; j++)
	{
        for (int k=0; k < option; k++)
		{
			if(isFaceUp[j][k])
				cout << garray[j][k];
			else
				cout << '*';
		}
	
	}
}
closed account (D80DSL3A)
Redirecting here from your other thread...
I am just confused on what a bool function is.

It's not clear to me either just what this required function should do, but I'm guessing that it should have a return type of bool. I made a guess in your other thread, which I'll re-post here:

1
2
3
4
5
// GameArray is passed to this function along with the users choices
bool isMatch( int GA[][SIZE], int row1, int col1, int row2, int col2 )
{
    return GA[row1][col1] == GA[row2][col2];
}

I think this function could be useful if you use it following line 56, but maybe the function required by your teacher is supposed to do more.

Some other comments:
It looks like the variable 'option' is used to vary the size of the puzzle from as small as 2x2 to as large as 10x10.
I see your function prototypes indicate that arrays with 10 elements per row will be passed:
1
2
void Shuffler (int garray[][10], int option);
void DisplayBoard( int garray[][10], bool isFaceUp[][10], int option);

You probably want to change SIZE to = 10 instead of 4. You could then just work with a smaller portion of this array when option is < 10, as you are doing in the DisplayBoard() function.
The displayBoard() doesn't make any use of the variables declared on lines 103-107, so you could get rid of those.

You probably meant to cin >> X2 and Y2 on lines 54 and 56.
Topic archived. No new replies allowed.