Advertisement

matching game

Started by January 12, 2022 01:45 AM
1 comment, last by Tom Sloper 2 years, 10 months ago

I am making a memory game using opengl and c++. I am able to post playing cards to the screen. I am having a problem posting two identical cards randomly to the screen. I am able to post 10 cards to the screen but the second 10 cards are posted blank. As you can see from my code the vector a creates the sequence of 20 values which is 10 pairs that is outputted randomly. can you please tell me why my previous question was locked. this seems like a valid question.

void init()
{
	// Step 1 
	int nPairs = 10;
	int nCards = nPairs * 2;
	vector<int> a;

	// Step 2. creates the sequence 0 0 1 1 2 2 3 3 4 4 ...
	for (int i = 0; i < nCards; i++)
	{
		a.push_back(i / 2); 	// or v.push_back(i >> 1);	
	}

	// Step 3
	random_device rd;
	mt19937 g(rd());
	shuffle(a.begin(), a.end(), g);

	// Step 4
	for (int i = 0; i < nCards; i++)
	{
		cout << a[i] << " ";
	}
		texture[a[0]] = loadTex("C:\\Users\\Owner\\Desktop\\2_of_clubs.png");
		texture[a[1]] = loadTex("C:\\Users\\Owner\\Desktop\\3_of_clubs.png");
		texture[a[2]] = loadTex("C:\\Users\\Owner\\Desktop\\4_of_clubs.png");
		texture[a[3]] = loadTex("C:\\Users\\Owner\\Desktop\\5_of_clubs.png");
		texture[a[4]] = loadTex("C:\\Users\\Owner\\Desktop\\6_of_clubs.png");
		texture[a[5]] = loadTex("C:\\Users\\Owner\\Desktop\\7_of_clubs.png");
		texture[a[6]] = loadTex("C:\\Users\\Owner\\Desktop\\8_of_clubs.png");
		texture[a[7]] = loadTex("C:\\Users\\Owner\\Desktop\\9_of_clubs.png");
		texture[a[8]] = loadTex("C:\\Users\\Owner\\Desktop\\10_of_clubs.png");
		texture[a[9]] = loadTex("C:\\Users\\Owner\\Desktop\\jack_of_clubs2.png");
		texture[a[10]] = loadTex("C:\\Users\\Owner\\Desktop\\queen_of_clubs2.png");
		texture[a[11]] = loadTex("C:\\Users\\Owner\\Desktop\\king_of_clubs2.png");
		texture[a[12]] = loadTex("C:\\Users\\Owner\\Desktop\\ace_of_clubs.png");
		texture[a[13]] = loadTex("C:\\Users\\Owner\\Desktop\\2_of_diamonds.png");
		texture[a[14]] = loadTex("C:\\Users\\Owner\\Desktop\\3_of_diamonds.png");
		texture[a[15]] = loadTex("C:\\Users\\Owner\\Desktop\\4_of_diamonds.png");
		texture[a[16]] = loadTex("C:\\Users\\Owner\\Desktop\\5_of_diamonds.png");
		texture[a[17]] = loadTex("C:\\Users\\Owner\\Desktop\\6_of_diamonds.png");
		texture[a[18]] = loadTex("C:\\Users\\Owner\\Desktop\\7_of_diamonds.png");
		texture[a[19]] = loadTex("C:\\Users\\Owner\\Desktop\\8_of_diamonds.png");
}

Just no.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement