I'm new to c++ and we have to make a memory matching game. We are supposed to use a one dimensional array but have it print out so it looks like a 4x4 game board. So far i have initialized the array and shuffled it. I also have the user input two choices which can correspond to a point in the array. I can display a board but its ugly. I'm stuck right now i think i need to have a boolean function to use with another array or something, any help as to where to go from here would be greatly appreciated.
Thanks.
CODE
/ ********************************************************************************
*****
Homework Assignment 9: Memory Matching Game
CSE 1100C: Introduction to Computing
Fall 2008
Objective: Develop modular programming skills using functions and develop competence
in using arrays, random numbers.
********************************************************************************
*****/
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
void shuffle(int [], int);
void displayBoard(const int [], int [], int, int, int);
void clearScreen();
bool checkGameStatus(const int [], int);
int main()
{
int size = 16;
int board[16]={1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8};
int showBoard[16];
int guesses=0;
shuffle(board,size); //Shuffle board[]
int n =0;
for(int i=0;i<16;i++){
cout<<board[i]<<" ";
n++;
if(n==4||n==8||n==12){
cout<<endl;
}
};
int continueGame, i1, i2, ii1, ii2, choice1, choice2;
do{
cout<<endl<<"Please input your coordinates x and y: "<<endl;
cout<<"x coordinate: ";
cin>>i1;
cout<<"y coordinate: ";
cin>>i2;
if(i1==1&&i2==1){choice1 = 0;}
if(i1==1&&i2==2){choice1 = 1;}
if(i1==1&&i2==3){choice1 = 2;}
if(i1==1&&i2==4){choice1 = 3;}
if(i1==2&&i2==1){choice1 = 4;}
if(i1==2&&i2==2){choice1 = 5;}
if(i1==2&&i2==3){choice1 = 6;}
if(i1==2&&i2==4){choice1 = 7;}
if(i1==3&&i2==1){choice1 = 8;}
if(i1==3&&i2==2){choice1 = 9;}
if(i1==3&&i2==3){choice1 = 10;}
if(i1==3&&i2==4){choice1 = 11;}
if(i1==4&&i2==1){choice1 = 12;}
if(i1==4&&i2==2){choice1 = 13;}
if(i1==4&&i2==3){choice1 = 14;}
if(i1==4&&i2==4){choice1 = 15;}
cout<<"Please input your second choice of coordinates x and y: "<<endl;
cout<<"x coordinate: ";
cin>>ii1;
cout<<"y coordinate: ";
cin>>ii2;
if(ii1==1&&ii2==1){choice2 = 0;}
if(ii1==1&&ii2==2){choice2 = 1;}
if(ii1==1&&ii2==3){choice2 = 2;}
if(ii1==1&&ii2==4){choice2 = 3;}
if(ii1==2&&ii2==1){choice2 = 4;}
if(ii1==2&&ii2==2){choice2 = 5;}
if(ii1==2&&ii2==3){choice2 = 6;}
if(ii1==2&&ii2==4){choice2 = 7;}
if(ii1==3&&ii2==1){choice2 = 8;}
if(ii1==3&&ii2==2){choice2 = 9;}
if(ii1==3&&ii2==3){choice2 = 10;}
if(ii1==3&&ii2==4){choice2 = 11;}
if(ii1==4&&ii2==1){choice2 = 12;}
if(ii1==4&&ii2==2){choice2 = 13;}
if(ii1==4&&ii2==3){choice2 = 14;}
if(ii1==4&&ii2==4){choice2 = 15;}
guesses++;
displayBoard(board, showBoard, choice1, choice2, size);
cout<<endl<<"would you like to continue '1' for yes '0' for no"<<endl;
cin>> continueGame;
if(continueGame!=0&&continueGame!=1){
cout<<"please input '1' or '0'"<<endl;
cin>> continueGame;}
}while(continueGame!=0);
cout<<"Number of guesses taken: "<<guesses<<endl;
}
void shuffle(int board[16], int size)
{
int temp,x;
srand(time(0));
for (int i=0;i<100;i++)
{
x = rand()%16;
temp = board[x];
board[x]=board[0];
board[0]=temp;
}
}
void displayBoard(const int board[], int showBoard[], int choice1, int choice2, int size)
{
int m =0;
cout<<endl<<endl;
cout << " 1 2 3 4 \n";
cout << " _______\n";
cout<<endl<<"1 | ";
for(int i=0;i<16;i++){
showBoard[i]=0;
showBoard[choice1]=board[choice1];
showBoard[choice2]=board[choice2];
cout<<showBoard[i]<<" ";
m++;
if(m==4){
cout<<endl<<"2 | ";}
if(m==8){
cout<<endl<<"3 | ";}
if(m==12){
cout<<endl<<"4 | ";}
}
cout<<endl<<endl;
}
void clearScreen()
{
}
bool checkGameStatus(const int arr[], int n)
{
return 0;
}