Answered step by step
Verified Expert Solution
Question
1 Approved Answer
GOAL - - - - - - - - - - - - - - - - - - - - - - - -
GOAL
A template has been given for this assignment
We will be creating a program that simulates a simple memory game. In this memory game, a grid of face
down cards is created. Every element of the grid has a matching pair. The user's goal is to find the
location of all pairs. For example,
For every iteration of a loop, the grid is displayed, and the user is prompted to enter two coordinates; x
and y where x is for row and y is for column.
For example, the coordinates could be row column and start at
Once the coordinates are entered, the two cards at the corresponding coordinates will be compared to each
other
If the cards match each other, the user has found a pair, so we keep them flipped over
If the cards do not match, we temporarily show the user the values of the cards at the coordinates,
and then we flip the cards over again
This loop should continue until the user finds all the pairs, or until they choose to quit.
OUR APPROACH
One "difficult" part of this lab is figuring out how to keep track of what cards have been found and what
cards haven't.
Remember that matched pairs need to be displayed, while all other pairs should be hidden. For example,
User matched a pair
So how to we keep track of what numbers to display and what numbers to put stars over? The approach
used in the program below is to maintain two separate D arrays: one will hold the actual numerical
values and the other will hold booleans that represent whether or not the value has been matched. Think
back to parallel D arrays. This is a similar approach.
THE FLOW OF OUR PROGRAM
Welcome the user and ask him to enter his full name.
Create D array of values. First put everything in order and shuffle the location of the elements. This
step is given.
Create the D array of Booleans that represents whether or not the card is matched. This should be
initialized to all FALSE at first. Why? Because no cards are matched initially!
Start a while loop that does the following
a Display the current state of the game board. Remember that nonmatched pairs should be "facedown"
and that matched pairs should be "faceup"
b Prompt the user to enter the coordinates of two cards
c If the values of the two coordinates match, then say that a match has been found and flip the cards
over forever. If the values do not match, temporarily flip over the cards to show the user the values, then
flip them over again.
Save the users name and how many turns it took to win the game into an output text file. If he quits
before winning save Dont give up message in the file.
A template for the assignment is provided. You must not delete any code there. You might delete the
commetns.
You must have at least three functions:
void InitializeCardsint cardsLENGTH;
void ShowCardsint cardsLENGTH bool faceupLENGTH;
int main
you may add more functions if you like.
Submit the cpp file only.
Snippets of a sample run:
Welcome to my game!
Please enter your full name: abeer alameer
Find all the matching pairs on the board!
Enter x and y position of the first card:
Enter x and y position of the second card:
No match.
Flipping cards over again.
Enter q to quit or press any key to continue...
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started