hey guys i gt this prac for campus plsss help here the question:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
You are going to write the memory game (with a deck of cards). Create an array of type integers,
with 52 positions. Each suit is represented by a set of 13 numbers. The first thirteen numbers are
Ace to King of hearts. The second thirteen numbers (14 to 26) are diamonds, the third set of thirteen
are spades, and the fourth set of thirteen is clubs.
Write the following functions:
· To initialize the array.
· A function that takes an individual integer and determines the number on the card.
· A function that shuffles the array.
o To shuffle the array, choose two random positions in the array and swap the values.
· A function that will appropriately display the number and suite of a single card.
Now create a parallel array of type Boolean that represents whether or not each card has been matched. Initialize the array to false. Write the following functions:
· A check function that checks if every value in the array is true, because this is the end game
condition.
· A display function, which displays the entire array (6 elements per line), with appropriate
numbering, so that a user can select two positions.
o If the position has been matched, display an ‘X’.
o Otherwise display a “?”.
Now you can write the memory game. While the end game condition is not met:
· Display the Boolean array.
· Read in a position number
o While the number at that position has been matched, ask for a different number
· Read in a second position number
o While the number at that position has been matched, ask for a different number
· If the value of the cards at each position is the same, set the values of the Boolean array to
true at both positions.
· Display appropriate messages for matches and misses.
==============================================================================
my code so far
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void Intialize(int arr[])
{
for (int i = 0 ; i < 13 ; i++)
{
arr[i]= ( i +1);
//cout<<arr[i];
}
//cout<<endl;
for (int i = 0 ; i < 13 ; i++)
{
arr[i+13]= ( i +1);
//cout<<arr[i];
}
//cout<<endl;
for (int i = 0 ; i < 13 ; i++)
{
arr[i+26]= ( i +1);
//cout<<arr[i];
}
//cout<<endl;
for (int i = 0 ; i < 13 ; i++)
{
arr[i+39]= ( i +1);
//cout<<arr[i];
}
}
void ValueCard( int num)
{
char CardLet;
int CardVal;
switch (num)
{
case 1:
CardLet='A';
cout<<CardLet;
break;
case 2:
CardVal=2;
cout<<CardVal;
break;
case 3:
CardVal=3;
cout<<CardVal;
break;
case 4:
CardVal=4;
cout<<CardVal;
break;
case 5:
CardVal=5;
cout<<CardVal;
break;
case 6:
CardVal=6;
cout<<CardVal;
break;
case 7:
CardVal=7;
cout<<CardVal;
break;
case 8:
CardVal=8;
cout<<CardVal;
break;
case 9:
CardVal=9;
cout<<CardVal;
break;
case 10:
CardVal=10;
cout<<CardVal;
break;
case 11:
CardLet='J';
cout<<CardLet;
break;
case 12:
CardLet='Q';
cout<<CardLet;
break;
case 13:
CardLet='K';
cout<<CardLet;
break;
}
}
void Shuffle(int arr[])
{
//To shuffle the array, choose two random positions in the array and swap the values.
int position_1 , position_2,temp;
srand((unsigned)time(0));
position_1 = (rand () % 52) ;
srand((unsigned)time(0));
position_2 = (rand () % 52) ;
temp = position_1 ;
arr[position_2] = arr[temp];
temp = position_2;
arr[position_1] = arr[temp];
}
int main()
{
int arr[52] ;
Intialize(arr);
for(int i = 0 ; i < 52 ; i++)
{
Shuffle(arr) ;
}
for (int i = 0 ; i < 52 ; i++)
{
if( i % 13 == 0 )
{
cout<<endl;
}
ValueCard( arr[i]) ;
}
return 0;
}
|