rendered paste body/* CPP 230 - Fall 2007 Chapter 5 - Project 13 by: Joey Burgett Instructor: Mark Laffoon*/#include <cstdlib>#include <iostream>using namespace std;int matrix [] = { 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8 };int tokens [4][4];bool visible [4][4];int pairs=0;void MatrixAssign();void Scramble();void DisplayBoard(int tokens[][4]);bool FindPair(int,int,int,int);int main(){ srand(time(NULL)); Scramble(); MatrixAssign(); while(true==true){ if (pairs>7) { cout << "\nGame Over!\n" << endl; break; } DisplayBoard(tokens); int x1,y1,x2,y2; cout << "\nEnter X Coordinate 1: "; cin >> x1; if (x1<1) break; cout << "\nEnter Y Coordinate 2: "; cin >> y1; cout << "\nEnter X Coordinate 1: "; cin >> x2; cout << "\nEnter Y Coordinate 2: "; cin >> y2; if ((x1>4) || (x2>4) || (y1>4) || (y2>4) || (x2<0) || (y1<0) || (y2<0)) { cout << "\nCoordinates must be 1 thru 4!\n" << endl; } else { if (FindPair(x1-1,y1-1,x2-1,y2-1)==true) { cout << "Match Found!\n" << endl; pairs++; } } system("PAUSE"); } system("PAUSE"); return EXIT_SUCCESS;}void Scramble(){ int tmp [16]; for (int counter=0;counter<15;counter++) { tmp[0]=(rand()%15)+1; tmp[1]=matrix[tmp[0]]; tmp[2]=matrix[counter]; matrix[counter]=tmp[1]; matrix[tmp[0]]=tmp[2]; }}bool FindPair(int x1,int y1,int x2,int y2){ if (tokens[x1][y1]==tokens[x2][y2]) { visible[x1][y1]=true; visible[x2][y2]=true; return true; } else { return false; }}void MatrixAssign(){ int counter=0; for (int x=0;x<4;x++) { for (int y=0;y<4;y++) { tokens[x][y]=matrix[counter]; visible[x][y]=false; counter++; } }}void DisplayBoard(int tokens[][4]){ system("CLS"); int counter=0; cout << " | 1 2 3 4 \n"; cout << " ___________________\n"; for (int x=0;x<4;x++) { cout << " " << x+1 << " |"; for (int y=0;y<4;y++) { if (!visible[x][y]) { cout << " " << tokens[x][y] << " "; } else { cout << " * "; } counter++; } cout << "\n"; }}