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++

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education