Memory GameProject–Initializationand Display BoardUnit Test Some thought must be given to the data structures needed and how the computer will keep track of the play. The computer must keep track of two pieces of information about each card: the value of the card(an integer between 1 and 8)and its state (face up or face down). In order to keep this information in the 4x4 game board array utilize a struct that has a minimum of two fields, the value of the card and its state. The game must be initialized by distributing 8 values twice in a random fashion in the 4x4 array. Here is a link to a web page that has a very good discussion with examples of using the random number generator: How to Create a Random Number Generator in C++. There are two approaches to this task. The first approach is to loop twice through the 8 values and generate the row and column indexes randomly. Use a loop that checks to see if the generatedlocation is unoccupied. If it is, it stores the value and the loop ends. Otherwise, the loop continuesto generate random rows and columns until an unoccupied location is found. The second approach is to loop through the rows and columns and generate the card values. This approach requires that you keep track of how many times a card valuehas been generated, if it has been generated and placed twice, continue generating until an unused number has been produced. You will need to write a function to display the game board. If the card is in the face down state, it’s value will be hidden (by showing a default value such as ‘*’ or -1) when the game board is displayed. If the card is in the face up state, the value of the card is displayed. Your display function will also need to display the rows and column values so that the player will know how to enter them on the keyboard. Do not assume that the players will be aware of the offset that programmers use when dealing with arrays (i.e., that array indexes start at 0). Also, it is easier for the players to remember locations if one of the dimensions is displayed as a character ratherthan both as numbers. This is howrows and columns are displayed on a spreadsheet. The columns are usually denoted by a capital letter (A, B, C, etc.) and the rows are denoted by a number. The user specifies a cell using the column/row designation (e.g., A1, B3, etc.). This is not how a programmer uses indexes, but the point is to make the program “user-friendly” not“easy for the programmer.” For the first unit test set up a mainfunction which declaresthe board structurethen calls the initializeBoard() function.Use the displayBoard()functionto display the initial version of the board, all the cards should be in the face down state. After this call, put some code in the main function to set the state of the cards to face up. Then call the displayBoard() functionagainand verify that the board has been initialized correctly (the numbers 1 –8 appear exactly twice in the board).    C++

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.4: Arrays As Arguments
Problem 6E: (Electrical eng.) Write a program that declares three one-dimensional arrays named volts, current,...
icon
Related questions
Question

Memory GameProject–Initializationand Display BoardUnit Test

Some thought must be given to the data structures needed and how the computer will keep track of the play. The computer must keep track of two pieces of information about each card: the value of the card(an integer between 1 and 8)and its state (face up or face down). In order to keep this information in the 4x4 game board array utilize a struct that has a minimum of two fields, the value of the card and its state.

The game must be initialized by distributing 8 values twice in a random fashion in the 4x4 array. Here is a link to a web page that has a very good discussion with examples of using the random number generator: How to Create a Random Number Generator in C++.

There are two approaches to this task.

The first approach is to loop twice through the 8 values and generate the row and column indexes randomly. Use a loop that checks to see if the generatedlocation is unoccupied. If it is, it stores the value and the loop ends. Otherwise, the loop continuesto generate random rows and columns until an unoccupied location is found.

The second approach is to loop through the rows and columns and generate the card values. This approach requires that you keep track of how many times a card valuehas been generated, if it has been generated and placed twice, continue generating until an unused number has been produced.

You will need to write a function to display the game board. If the card is in the face down state, it’s value will be hidden (by showing a default value such as ‘*’ or -1) when the game board is displayed. If the card is in the face up state, the value of the card is displayed.

Your display function will also need to display the rows and column values so that the player will know how to enter them on the keyboard. Do not assume that the players will be aware of the offset that programmers use when dealing with arrays (i.e., that array indexes start at 0). Also, it is easier for the players to remember locations if one of the dimensions is displayed as a character ratherthan both as numbers. This is howrows and columns are displayed on a spreadsheet. The columns are usually denoted by a capital letter (A, B, C, etc.) and the rows are denoted by a number. The user specifies a cell using the column/row designation (e.g., A1, B3, etc.). This is not how a programmer uses indexes, but the point is to make the program “user-friendly” not“easy for the programmer.”

For the first unit test set up a mainfunction which declaresthe board structurethen calls the initializeBoard() function.Use the displayBoard()functionto display the initial version of the board, all the cards should be in the face down state. After this call, put some code in the main function to set the state of the cards to face up. Then call the displayBoard() functionagainand verify that the board has been initialized correctly (the numbers 1 –8 appear exactly twice in the board). 

 

C++

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage