Hello I'm having issue with this assignment. My program is a Memory Match Game in C++, and it runs, however I need to get the chars in my 2D array to shift positions after every time the user inputs a valid or invalid response. They're staying at the same position as initialized. I've tried multiple ideas but have come to no conclusions. Even some hints that might help are appreciated.
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;
class Game //Memory Match Game
{
private:
char cards[4][4] = { { '@', '#', '$', '%' },
{'^', '&', '*', '+'},
{'@', '#', '$', '%'},
{'^', '&', '*', '+' } };
char deck[16] = { '@','#', '$', '%', '^','&', '*', '+' }; //not being used atm
int r1, r2, c1, c2;
public:
Game()
{
r1 = 0; r2 = 0; c1 = 0; c2 = 0;
}
void begin()
{
srand((unsigned)time(NULL));
for (int x = 0; x < 4; x++) //begin designating cards
{
for (int y = 0; y < 4; y++)
{
cards[rand() % x][rand() % y]; // <:::::[:::] FIX
cout << " " << cards[x][y] << " ";
}
cout << endl;
}
cout << " \n 1 2 3 4\t\n";
cout << " ";
for (int x = 0; x <= 8; x++)
{
cout << "_";
}
cout << endl;
for (int x = 0; x < 4; x++) //appropriate positioning
{
cout << x + 1 << " | ";
for (int y = 0; y < 4; y++)
{
cout << "? ";
}
cout << endl;
}
cout << endl;
input();
}
void input()
{
srand(time(0));
cout << "Please type in the row and column of choice.\n"; //begin user play
cin >> r1;
cin >> c1;
cout << "Please type in the row and column of choice\n";
cin >> r2;
cin >> c2;
r1--; r2--; c1--; c2--;
cout << " 1 2 3 4\n";
cout << " ";
for (int x = 0; x <= 8; x++)
{
cout << "_";
}
cout << endl;
for (int x = 0; x < 4; x++)
{
cout << x + 1 << " | ";
for (int y = 0; y < 4; y++)
{
if ((x == r1) && (y == c1))
{
cout << cards[x][y] << " ";
}
else if ((x == r2) && (y == c2))
{
cout << cards[x][y] << " ";
}
else cout << "? ";
}
cout << endl;
}
match();
}
void match()
{
if (cards[r1][c1] == cards[r2][c2])
{
cout << "Valid Match!\n";
input();
}
else
cout << "Invalid Match!\n";
input();
}
};
int main()
{
Game memoryMatch;
memoryMatch.begin();
system("pause");
}