Memory Matching Game C++

Hello all,

I have a Memory Matching Game C++ project in my programming class due tomorrow and am a bit stuck. I have tried to manipulate the code by myself but have been having a great deal of difficulty. I have also obtained useful information from another user on this forum, but have yet to complete the code. The following is the project assignment, and I have the code written so far. Thank you very much in advance and appreciate any help.

Select a Theme and have 50 words associated with it
Words must have a common theme - your choice

Examples: Like Periodic Table Elements, or Sports teams, or Types of cars…
Have one Term describing category you picked. This is the FACE term…

Menu:
Start Button
New Game Button
Exit Game Button

Level of Play – Use selects at start of game
4 x 4 grid (Easy)
6 x 6 grid (Moderate)
8 X 8 grid (Difficult)

Speed of Play – At start of game, User selects time interval for clicked-on term-pair to display
1 seconds (Difficult)
3 seconds (Moderate)
5 seconds (Easy)

Populate Grid with Term
At start of game – program places the same face/theme term in all squares in the visible grid

If 4 x 4 grid, randomly pick 8 terms, place each image name twice in 2-Dim array.
If 6 x 6 grid, randomly pick 18 terns, place each image name twice in 2-Dim array.
If 8 x 8 grid, randomly pick 32 terms, place each image name twice in 2-Dim array.
The 2-Dim Array corresponds to grid on screen.

During the course of play, the face/theme term in the grid is replaced by a
corresponding array terms, when user selects a grid square

Game Play

1) User selects a FIRST square, the theme/face term in the grid square is replace with correspond stored term, from the 2-dim array

2) User selects a SECOND square, the term theme/face in the second grid square is replace with the corresponding stored term, from the 2-dim array

3) The computer compares the terms for the two selected squares.
If they are the same, the terms remain on the screen and can no longer be selected.

If they are different, the term remain the screen for 1, 3 or 5 seconds, depending on user selection at the beginning of the game. After that elapse time, those two grid terms are replaced with the face/theme term.




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
#include "stdafx.h"
#include <string>
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

void gridEasy(void);
void randomizeTheme(string theme[]);


int main()
{
	string theme[16] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p" };

	int grid;
	bool firstRun = true;

	cout << "Please choose your grid: " << endl << endl;
	cout << "1. 4 x 4 grid (Easy)" << endl;
	cout << "2. 6 x 6 grid (Medium)" << endl;
	cout << "3. 8 x 8 grid (Hard)" << endl << endl;

	cin >> grid;

	if (grid == 1)
	{
		return 16;
	}

	else if (grid == 2)
	{
		return 32;
	}

	else if (grid == 3)
	{
		return 64;
	}

	else
	{
		do
		{
			cout << "Please choose your grid: " << endl << endl;
			cout << "1. 4 x 4 grid (Easy)" << endl;
			cout << "2. 6 x 6 grid (Medium)" << endl;
			cout << "3. 8 x 8 grid (Hard)" << endl << endl;

			if (!firstRun)
			{
				system("CLS");
				cout << "Not a correct response, please try again." << endl;
				cin.clear();
				cin.ignore(INT_MAX, '\n');
			}
			firstRun = false;
		} while (!(cin >> grid));


		gridEasy();
		srand(time(0));
		randomizeTheme(theme);
		for (int i = 0; i < 16; i++)
		{
			cout << theme[i] << endl;
		}
		system("Pause");
		return 0;
	}
}


void gridEasy(void)
{
	for (int r = 0; r < 4; r++)
	{
		for (int c = 0; c < 4; c++)
		{

			cout << "-----------------------------" << endl;
			cout << "|" << setw(9) << r + 1 << setw(9) << "|" << endl;
			cout << "-----------------------------" << endl;
		}
	}

	cout << "--------------------------------------------------------------------------------";
}

void randomizeTheme(string theme[])
{
	random_shuffle(theme, theme + 16);
}
Last edited on
Topic archived. No new replies allowed.