Question
A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given six
A common memory matching game played by young children is to start with a deck of cards that contain identical pairs. For example, given six cards in the deck, two might be labeled 1, two labeled 2, and two labeled 3. The cards are shuffled and placed face down on the table. A player then selects two cards that are face down, turns them face up, and if the cards match, they are left face up. If the two cards do not match, they are returned to their original face down position. The game continues until all cards are face up. Write a Java program that plays the memory matching game. Use 16 cards that are laid out in a 4 4 square and are labeled with pairs of numbers from 1 to 8. Your program should allow the player to specify the cards that he or she would like to select through a coordinate system. For example, in the following layout,
1 2 3 4 1 8 * * * 2 * * * * 3 * 8 * * 4 * * * *
all of the face down cards are indicated by *. The pairs of 8 that are face up are at coordinates (1,1) and (3,2). To hide the cards that have been temporarily placed face up, output a large number of newlines to force the old board off the screen.
run: 1 2 3 4 2 Enter the first coordinate pair (x y); each coordinate is in 1...4: 1 1 Enter the first coordinate pair (x y); each coordinate is in 1..4: 2 2 1 2 3 4 1 3 Hit Enter to continue... Lots of blank Lines here 1 2 3 4 2 Enter the first coordinate pair (x y); each coordinate is in 1..4: 1 1 Enter the first coordinate pair (x y); each coordinate is in 1..4: 2 3 1 2 3 4 1 3 26 Hit Enter to continue... Lots of blank Lines here 1 2 3 4 Enter the first coordinate pair (x y); each coordinate is in 1...4: 1 1 Enter the first coordinate pair (x y); each coordinate is in 1..4: 3 3 1 2 3 4 1 3 2 Hit Enter to continue... Lots of blank Lines here 1 2 3 4 1 3
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