matching game: keeping matches visible

Win32 console text based matching game:

I have a somewhat working matching game, but I have a few ?'s:

Is there a way to shuffle a 2d array randomly each start of the game?

Also, once they have a match, I want the matches names to stay open...
While if they are not, I want them to stay open for 3 seconds before hiding again.

Currently my shuffle only shuffles my 2d array by row, not row and columns(by individual index), so as long as my array is already shuffles at initialization, shuffling by row works. But a shuffle that would shuffle each individual index is what would be best..

(My teach demands a 2d array)
@breich2

I threw together a small word shuffling program. Hopefully, you'll be able to adapt it to your program. Showing and then hiding, would require a gotoXY() function, where you would print the array at a location, then overwrite it with x's or something, to hide the words, if they're not the same.

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
#include <iostream>
#include <string>
#include <ctime>

using  std::cout;
using std::endl;
using std::string;

void Shuffle_Array(string words[4][4]);

int main()
{
	srand((unsigned)time(0)); // randomize using time as seed

       string words[4][4] = {
		{ "One", "One", "Two", "Two" },
		{ "Three", "Three", "Four", "Four" },
		{ "Five", "Five", "Six", "Six" },
		{ "Seven", "Seven", "Eight", "Eight" }
	};

	
	cout << "Unshuffled word array..." << endl << endl;
	for (int a = 0; a < 4; a++)
	{
		for (int b = 0; b < 4; b++)
		{
			cout << words[a][b] << " ";
		}
		cout << endl;
	}

	Shuffle_Array(words);

	cout << endl << endl << "Now, the shuffled word array..." << endl << endl;
	for (int a = 0; a < 4; a++)
	{
		for (int b = 0; b < 4; b++)
		{
			cout << words[a][b] << " ";
		}
		cout << endl;
	}
	return 0;
}

void Shuffle_Array(string words[4][4])
{
	int a1, b1, a2, b2;
	string temp1;
	for (int x = 0; x < 150; x++)
	{
		a1 = rand() % 4;
		a2 = rand() % 4;
		
		b1 = rand() % 4;
		b2 = rand() % 4;
		temp1 = words[a1][a2];
		words[a1][a2] = words[b1][b2];
		words[b1][b2] = temp1;
	}
}
Last edited on
Still not it completely, but beautiful code... that was a better shuffle than what I had... I was close to yours, I basically had everything but use of rand() right...

but your gotoxy idea wont work for me. I got it to work, and I've use it before in html, but that's not what I need. That just places the words at a certain place by index of the grid of the entire winconsole. Like, as if the console was a grid, like 10000x100000, and the gotoxy just places it at co-ordinates on that grid. Did you think I had problems filling my grid? No, my grid is filled, my game works, it just doesn't have the flashier details I need for this.

I have a grid like this:

|xxxxxx|xxxxxx|xxxxxx|xxxxxx|

except even x's and all that, and first names are pitched into them. They pick a row/colomn to choose 2 boxes to try and match. There's a 4x4, 6x6, and an 8x8 grid of those^.

1) I need the matches to stay open when they match them.

2) I need the names to just flash for 1, 3, or 5 seconds(speed of game play) for names that DON'T MATCH.

I already have the game working, just not with these REQUIREMENTS for me.. and i'm frustrated.


I've looked everywhere and tried it myself, but these two I can't manage, but can't do without. I REALLY need these two... it's required. Any point to a correct tutorial or library would MUCH BE APPRECIATED!!

I also need timers, for how long it takes the use to complete a game, and how long it takes to complete a match. These i'm reading into currently. I've looked a lot for the two I listed before that and can't get it, hopefully I can get this timer stuff, but any direction there would help too.

Last edited on
Topic archived. No new replies allowed.