Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Find My Pair Game A common memory matching game played by children is to start w

ID: 3705353 • Letter: F

Question

Find My Pair Game A common memory matching game played by children is to start with a deck of identical pairs face down on a table. A player selects two cards and turns the face up. If they match, they remain face up. If they do not match, they are flipped face down. The game continues until all of the cards are face up. Write a program that plays this memory game. Use 8 cards laid out in a 2X4 rectangle and labeled with pairs of numbers from 1 to 4. Your program should allow the player to specify the cards that he or she would like to select through a coordinate system For example, suppose the cards are in the following layout 1 2 34 All of the cards are face down except the pair of 4 which the player found by entering (0, 0) and (1, . If the pair is mismatch, hide the cards that have been placed temporarily up. .If all cards are faced up, the player wins. Each turn is as follows: When program start ask user to input his/her name. . Use arrays and functions. .The program displays first all the cards and then deletes them, and player will make a guess. . The player turns two cards upright. If the cards are the same, then the cards remain upright. If the cards are different, then the cards are turned face down again. The cards always remain in the same relative position in the same execution of the program. The game stops when all cards have been matched. Once the game has concluded, display user name then ask the user if he/she wishes to play again. The next game shows the numbers in different order. . You may add different levels of difficulty by limiting the time to play the game (i.e. if time taken is too long and you are playing difficulty level 2, the game will automatically stop) Hint: You will need to remember the face value on the card, as well as whether the card is facing down or not.

Explanation / Answer

please rate - thanks

#include <iostream>
#include <ctime>
#include<iomanip>
using namespace std;
void shuffle(int[]);
void arrangedeck(int[],int[][4],bool[][4],int &,int &,int&,int &);
void print (bool[][4],int[][4]);
void getplay(int &,int &,int &,int&,bool[][4],int[][4]);
int get(string);
int main()
{
inti,j,row1,row2,col1,col2,prow1,prow2,pcol1,pcol2,deck[16],arr[4][4],show=2;
bool face[4][4]={false};
srand(time(0));
shuffle(deck);
/* cout<<"deck-after shuffled: ";
       for(j=0;j<16;j++)
          cout<<deck[j]<<endl;
       cout<<endl;
   */
arrangedeck(deck,arr,face,row1,row2,col1,col2);
/*for(i=0;i<4;i++)
   {for(j=0;j<4;j++)
       cout<<arr[i][j]<<"";
     cout<<endl;
     }
cout<<" ";
*/
print(face,arr);
while(show!=16)
{

if(arr[row1][col1]!=arr[row2][col2])
      {face[row1][col1]=false;
       face[row2][col2]=false;
       show-=2;
       }
getplay(row1,col1,row2,col2,face,arr);
show+=2;
}
cout<<"GAME OVER!!! ";      
system("pause");
return 0;
}
int get(string mess)
{int n;
do
{cout<<"Enter "<<mess<<": ";
   cin>>n;
      if(n<1||n>4)
         cout<<"Invalid ";
   }while(n<1||n>4);
return n-1;
}

void getplay(int& r1,int & c1,int &r2, int &c2,boolface[][4],int arr[][4])
{cout<<"Enter move ";
do
   {r1=get("row 1");
    c1=get("col 1");
    if(face[r1][c1])
        cout<<"Invalid move ";
   }while(face[r1][c1]);
face[r1][c1]=true;
cout<<" Enter move ";
print(face,arr);
do
   {r2=get("row 2");
    c2=get("col 2");
    if(face[r2][c2])
        cout<<"Invalid move ";
   }while(face[r2][c2]);
face[r2][c2]=true;
print(face,arr);
}

void print(bool face[][4],int arr[][4])
{int i,j;
for(i=0;i<30;i++)
     cout<<endl;
cout<<"     ";
for(i=1;i<5;i++)
     cout<<i<<" ";
cout<<"     --------- ";
for(i=0;i<4;i++)
   {cout<<" "<<i+1<<" | ";
   for(j=0;j<4;j++)
       if(face[i][j])
           cout<<arr[i][j]<<" ";
       else
           cout<<"* ";
     cout<<endl;
     }  
cout<<" ";
}

void arrangedeck(int deck[],int arr[][4],bool face[][4],int&r1,int &r2,int &c1,int &c2)
{int i,j,k;
k=0;
for(i=0;i<4;i++)
    for(j=0;j<4;j++)
        arr[i][j]=deck[k++];
i=rand()%16;
do
{j=rand()%16;
}while(i==j);
r1=i/4;
r2=j/4;
c1=i%4;
c2=j%4;
face[r1][c1]=true;
face[r2][c2]=true;
}


void shuffle(intdeck[])                 
{int cards[9];
int i,j,num,type;

   for(j=0;j<9;j++)
      cards[j]=2;

    for(j=0;j<16;j++)
        {do
           {
           num=rand()%8+1;
           
           }while(cards[num]==0);
      
         deck[j]=num;
         cards[num]--;
         }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote