Beruflich Dokumente
Kultur Dokumente
CLASS:XI(MATHS-I)
ROLL NO:48
SUBJECT:COMPUTER SCIENCE
MEMORY GAME
Requirements:
Your solution to your Final Project must be using a 'CLASS' and have all the
variables and functions ENCAPSULATED in your classes to get full credit.
Additionally, I will be looking for good comments, naming conventions, simplified
code/no duplication, validation of user inputs and testing the accuracy of the game
play. Additionally, The class you write
All your variables/arrays and functions are to be encapsulated inside the Memory
Match game class you write.
The int main() in your code contain only two lines of code::
#include iostream;
#include string;
#include MemoryMatchGame;
Int main() {
Timer (Extra credit) - Create/display a timer that keep track of the number of
seconds it took to win a game.
Select a Theme and have 50 words associated with it. (MAX individual word
length is 8 characters)
Have one Term describing category you picked. This is the FACE term…
4 x 4 grid (Easy)
6 x 6 grid (Moderate)
8 X 8 grid (Difficult)
Speed of Play – At start of game, User selects time interval for clicked-on term-
pair to display
2 seconds (Difficult)
4 seconds (Moderate)
6 seconds (Easy)
Optional feature (have more than one theme – User would select theme)
Next, Populate answer Grid with randomly selected Terms from the theme array
At start of game – program places the same face/theme term in all squares in the
visible grid
Answers not visible, only theme name is displayed in all squares, at start of game.
If 4 x 4 grid, randomly pick 8 terms, place each image name twice in 2-Dim array.
If 6 x 6 grid, randomly pick 18 terns, place each image name twice in 2-Dim array.
If 8 x 8 grid, randomly pick 32 terms, place each image name twice in 2-Dim
array.
Hint: Randomly shuffle theme array and just pick the first 8, or 18 or 32
terms per game player selection
During the course of play, the face/theme term in the display grid is replaced by a
Game Play
User selects a FIRST square, the theme/face term in the grid square is replace with
correspond stored term, from the 2-dim answer array
User selects a SECOND square, the term theme/face in the second grid square is
replace with the corresponding stored term, from the 2-dim answer array
The computer compares the terms for the two selected squares.
If they are the same, the terms remain on the screen and can no longer
be selected.
If they are different, the term remain the screen for 2, 4 or 6 seconds,
depending on user selection at the beginning of the game.After that
elapse time, those two grid terms are replaced with the face/theme term.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
char comma;
int r1, c1, r2, c2, cards[4][4];
srand((unsigned)time(NULL));
//fill board
for (int r=0; r<4; r++)
{
for (int c=0; c<4; c++)
{
cards[r][c]=rand()%8+1;
cout<<cards[r][c];
}
cout<<endl;
}
//display board
cout<<" 1 2 3 4\n";
cout<<" ";
for (int i=0; i<=8; i++)
{
cout<<"-";
}
cout<<endl;
for (int r=0; r<4; r++)
{
cout<<r+1<<" | ";
for (int c=0; c<4; c++)
{
cout<<"* ";
}
cout<<endl;
}
cout<<endl;
//selection
cout<<"Please insert the first card row and column seperated by a comma. \n";
cin>>r1>>comma>>c1;
cout<<"Please insert the second card row and column seperated by a
comma.\n";
cin>>r2>>comma>>c2;
//fix
r1--;
c1--;
r2--;
c2--;
//reveal
cout<<" 1 2 3 4\n";
cout<<" ";
for (int i=0; i<=8; i++)
{
cout<<"-";
}
cout<<endl;
for (int r=0; r<4; r++)
{
cout<<r+1<<" | ";
for (int c=0; c<4; c++)
{
if ((r==r1)&&(c==c1))
{
cout<<cards[r][c]<<" ";
}
else if((r==r2)&&(c==c2))
{
cout<<cards[r][c]<<" ";
}
else
{
cout<<"* ";
}
}
cout<<endl;
}
//match?
if (cards[r1][c1]==cards[r2][c2])
{
}
else
{
}
//this pushes the next board onto a blank screen
for (int b=0; b<=20; b++)
cout<<endl;
//repeat
return 0;
}