1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
// Use a char array for the bool for when face up and have that connect to the int array if choosen correctly
#include<iostream>
#include<fstream>
using namespace std;
void Shuffler (int garray[][10], int option);
void DisplayBoard( int garray[][10], bool isFaceUp[][10], int option);
// These functions may or may not be used after editing
void Print2DArray(int arr1[][10], int r, int c);
int Fill_array( int array1[][10], int no_rows, int no_cols);
const int SIZE = 4;
int main ()
{
int rows, cols, max, option, X1, Y1,X2, Y2, GameArray[SIZE][SIZE];
bool isFaceUp[SIZE][SIZE]; // declaration for the number of rows and columns and the array size of 20 rows and 15 columns as a max
for(int i = 0; i < SIZE; i++) //set all values of isFaceUp to false so all cards are face down
{
for(int a = 0; a <SIZE; a++)
{
isFaceUp[i][a] = false;
}
}
cout << "Please enter the type of game you would like to play by choosing either a 2, 4, 6, 8 or 10." << endl;
cin >> option;
while ( (option != 2) || (option != 4) || (option != 6) || (option != 8) || (option != 10) )
{
cout << "You have entered an invalid number. Please try again." << endl;
cin >> option;
}
Shuffler ( GameArray, option); // Shuffle the values in the array
// Show the table to the player
cout << "Please indicate the first card you would like to flip over by entering the X and Y coordinate." << endl;
cout << "Enter the X coordinate." << endl;
cin >> X1;
cout << "Enter the Y coordinate." << endl;
cin >> Y1;
cout << "Please indicate the second card you would like to flip over by entering the X and Y coordinate." << endl;
cout << "Enter the X coordinate." << endl;
cin >> X1;
cout << "Enter the Y coordinate." << endl;
cin >> Y1;
DisplayBoard(GameArray, isFaceUp, option);
// input the number of columns
//call function to fill array
Fill_array( GameArray, option, option);
//call function to print array
cout << "Below is the given values for your array." << endl;
Print2DArray( GameArray, rows, cols);
}
// functions found below
void Shuffler (int garray [][SIZE], int option)
{
int a = 1;
for (int i = 0; i < option; i++)
{
if(i == option/2)
a = 0;
for(int r = 0; r < option; r++)
{
garray[i][r] = a;
a++;
}
}
for(int i = 0; i < option; i++)
{
int a, b, c, d, e;
a = rand()% option;
b = rand() % option;
c = rand()% option;
d = rand() % option;
e = garray[a][b];
garray[a][b] = garray[c][d];
garray[c][d] = e;
}
}
void DisplayBoard( int garray[][SIZE], bool isFaceUp[][SIZE], int option)
{
const int ARRAY_SIZE = option;
const int NUMS_USED = option * 2;
int array[SIZE][SIZE];
bool arrayBool[SIZE][SIZE];
bool arrayAvail[SIZE][SIZE];
for (int j = 0; j < option; j++)
{
for (int k=0; k < option; k++)
{
if(isFaceUp[j][k])
cout << garray[j][k];
else
cout << '*';
}
}
}
|