Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop an NxN memory card game and allow 2-4 players to play. On the face of each card is a single letter, A-Z. The cards

Develop an NxN memory card game and allow 2-4 players to play. On the face of each card is a single letter, A-Z. The cards are shuffled and randomly placed face down in N-column and N-row grid. Players take turn to pick two cards at each turn. Whenever a player picks 2 cards with matching letters, the cards are placed face up, and the player earns one point. The player gets to pick another pair repeatedly until the letters do not match or there are no more cards to pick. The game can be placed at 2 levels:

Level 1 N is 4, resulting in a 4x4 grid. Letters are randomly chosen and assigned to either 2 cards or 4 cards, repeatedly until 16 cards have been assigned letters. Level 2 N is an integer between 2 to 7. If the number of cells in the grid is odd, the last grid position is left empty and is marked NIL so only an even number of cards will be used in each game. For example, when N is 3, 5 or 7, there are 8, 24 or 48 cards respectively. Letters are randomly chosen and assigned to either only 1 card or 2 cards. The letters on cards may come in pairs (50% chance) or there can be exactly 2 letters without a match (50% chance).

Implement the memory card game. Your collections can be ONLY of these types: unnested lists, dict or str collections. Note: The implementation of level 2 game play is worth 14 marks. You may implement level 1 first and then build level 2 on top of the implementation for level 1. - Start the application by getting the names of the players. There should be 2 to 4 players with no repeating names. The same set of players will play one or more memory games until the application ends. Before each new game commences, the application randomly orders the players, and this will be the order that the players take their turn. - Allow the player to choose a game level. If the input is invalid, allow data entry to be repeated. The valid game level is either 1 or 2. If the game level is 1, do not prompt for grid size. If the game level is 2, the players choose a grid size. If the input is invalid, allow data entry to be repeated. The valid grid size is between 2 and 7. The application generates the cards according to the grid size (4x4 for level 1) and the constraints as specified for the game level, and the cards are shuffled.

- The application displays the cards face down and matched cards are displayed face up. Display NIL in the last grid position when N is odd (for level 2).

- At the start of each game, display a cheat sheet to help you test your program. The players take turn to pick until there are no more cards to pick (for both levels) or when the last two remaining cards do not match (for level 2 only). Display the score of a player when it is the players turn to pick two cards. To pick a card, the player specifies the row and column numbers. Validate the row and column numbers, e.g., not NIL (for level 2 only), not a card that is already placed face up (for both levels), not outside grid boundary (for both levels) and the two cards picked are different cards. Display the updated score if the picked cards match.

- When the game ends, display the players with the most pairs of cards matched, in alphabetical order of names of players that tie. Then prompt whether the players wish to play a new game. If so, allow the players to choose a grid size and the game level. Example run:

Enter player name or to exit (min 2, max 4 players):

Minimum 2 players. Currently, 0 player

Enter player name or to exit (min 2, max 4 players): ben

Enter player name or to exit (min 2, max 4 players):

Minimum 2 players. Currently, 1 player

Enter player name or to exit (min 2, max 4 players): BEN

Repeated name. Choose another name

Enter player name or to exit (min 2, max 4 players): cindy

Enter player name or to exit (min 2, max 4 players): alan

Enter player name or to exit (min 2, max 4 players):

Enter game level(1 to 2): -1

Please enter a valid game level

Enter game level(1 to 2): 3

Please enter a valid game level

Enter game level(1 to 2): 1

*** Cheat Sheet ***

image text in transcribed

-----------------------

*** End Cheat Sheet ***

image text in transcribed

Player Cindy, enter your guess

Current number of correct pairs: 0

Enter first card row and column, separated by space: 10 10

Please choose a card row and column within the grid

Enter first card row and column, separated by space: 1 1

Open H

Enter second card row and column, separated by space: 1 1

Please choose a different row and column from your earlier choice

Enter second card row and column, separated by space: 4 4

Open H

Correct !!!!

Updated number of correct pairs: 1

image text in transcribed

Player Cindy, enter your guess

Current number of correct pairs: 1

Enter first card row and column, separated by space: 1 1

Please choose a card that is not face up yet

Enter first card row and column, separated by space: 2 3

Open T

Enter second card row and column, separated by space: 2 4

Open T

Correct !!!!

Updated number of correct pairs: 2

image text in transcribed

Player Cindy, enter your guess

Current number of correct pairs: 2

Enter first card row and column, separated by space: 1 2

Open S

Enter second card row and column, separated by space: 1 3

Open I

Non-matching. No update

image text in transcribed

Player Alan, enter your guess

Current number of correct pairs: 0

Enter first card row and column, separated by space: 1 2

Open S

Enter second card row and column, separated by space: 1 4

Open S

Correct !!!!

Updated number of correct pairs: 1

image text in transcribed

Player Alan, enter your guess

Current number of correct pairs: 1

Enter first card row and column, separated by space: 1 3

Open I

Enter second card row and column, separated by space: 3 4

Open I

Correct !!!!

Updated number of correct pairs: 2

image text in transcribed

Player Alan, enter your guess

Current number of correct pairs: 2

Enter first card row and column, separated by space: 2 1

Open V

Enter second card row and column, separated by space: 2 2

Open G

Non-matching. No update

image text in transcribed

Player Ben, enter your guess

Current number of correct pairs: 0

Enter first card row and column, separated by space: 2 2

Open G

Enter second card row and column, separated by space: 3 2

Open G

Correct !!!!

Updated number of correct pairs: 1

image text in transcribed

Player Ben, enter your guess

Current number of correct pairs: 1

Enter first card row and column, separated by space: 4 2

Open I

Enter second card row and column, separated by space: 4 3

Open I

Correct !!!!

Updated number of correct pairs: 2

image text in transcribed

Player Ben, enter your guess

Current number of correct pairs: 2

Enter first card row and column, separated by space: 3 1

Open O

Enter second card row and column, separated by space: 4 1

Open O

Correct !!!!

Updated number of correct pairs: 3

image text in transcribed

Player Ben, enter your guess

Current number of correct pairs: 3

Enter first card row and column, separated by space: 2 1

Open V

Enter second card row and column, separated by space: 3 3

Open V

Correct !!!!

Updated number of correct pairs: 4 Game ends!

image text in transcribed

Winners with 4 matched pairs: Ben

Play again? an empty string to play again:

Enter game level(1 to 2): 2

Enter grid size(2 to 7): 8

Please enter a valid grid size

Enter grid size(2 to 7): 0

Please enter a valid grid size

Enter grid size(2 to 7): 3

*** Cheat Sheet *** image text in transcribed

image text in transcribed

Player Ben, enter your guess

Current number of correct pairs: 0

Enter first card row and column, separated by space: 3 3

Please choose a different row and column that is not for NIL

Enter first card row and column, separated by space: -1 -1

Please choose a card row and column within the grid

Enter first card row and column, separated by space: 2 1

Open K

Enter second card row and column, separated by space: 3 1

Open K

Correct !!!!

Updated number of correct pairs: 1

image text in transcribed

Player Ben, enter your guess

Current number of correct pairs: 1

Enter first card row and column, separated by space: 1 2

Open E

Enter second card row and column, separated by space: 1 3

Open P

Non-matching. No update

image text in transcribed

Player Cindy, enter your guess

Current number of correct pairs: 0

Enter first card row and column, separated by space: 2 1

Please choose a card that is not face up yet

Enter first card row and column, separated by space: 2 2

Open W

Enter second card row and column, separated by space: 1 1

Open W

Correct !!!!

Updated number of correct pairs: 1

image text in transcribed

Player Cindy, enter your guess

Current number of correct pairs: 1 Enter first card row and column, separated by space: 2 3

Open O

Enter second card row and column, separated by space: 1 3

Open P

Non-matching. No update

image text in transcribed

Player Alan, enter your guess

Current number of correct pairs: 0

Enter first card row and column, separated by space: 2 3

Open O

Enter second card row and column, separated by space: 3 2

Open O

Correct !!!!

Updated number of correct pairs: 1

Remaining two cards are non-matching: E and P

image text in transcribed

Winners with 1 matched pairs: Alan, Ben, Cindy

Play again? an empty string to play again: n

Memory Game terminating

Columns Rows | 1 | 2 | 3 | 4 | 1| H|SI|| 2 v | G|TT| 310 | G | v |I| 4 0 | 11H Starting new game Columns Rows | 1 | 2 | 3 | 4 11 | | 2 1 31 | | 41 1 - - - - ! - Columns Rows | 1 | 2 | 3 | 4 | 1] HIT 1 21 | 31 1 | 41 | HI - Columns Rows | 1 | 2 | 3 | 4 | 1| H | 1 1 | 21 | |TT TI 31 | - - - 41 1 TH - - - - - - Columns Rows | 1 | 2 | 3 | 4 | 11 H1 | 2 | 31 41 | HT Columns Rows | 1 | 2 | 3 | 4 | 10 HS 1 Isl 21 1 | | | | 31 | 41 IL | H | - - - - Columns Rows | 1 | 2 | 3 | 4 | 1| H|S|1s| 21 ITTI 31 |I| 41 1 | | HI - - - - - - Columns Rows | 1 | 2 | 3 | 4 | 1] HS1S 21 | |TT| 31 | 1 I 41 | H - - - - - Columns Rows | 1 | 2 | 3 | 4 | 1] H5|1s| 21 | GTTI | GT |I| 41 | HI Columns Rows | 1 | 2 | 3 | 4 | 1 HSIS 2 | GOTTI 31 | G| |I| 4 |1|1|H| Columns Rows | 1 | 2 | 3 | 4 | 1HS|I|S| 21 | GOTTI 300 G | |I| 40|1|I|H| Columns Rows | 1 | 2 | 3 | 4 | 1] HS|IS| 2 v | G|TT| 31 O | G | v |I| 4 0 | I|IH Columns Rows | 1 | 2 | 3 | 10 W EPI 2 KW OL 3 K | O NILI *** End Cheat Sheet *** Starting new game Columns Rows | 1 | 2 | 3 | 11 II | 21 | 31 | INIL - ! - Columns Rows | 1 | 2 | 3 | 11 | | 2KI | 3 K | NIL Columns Rows | 1 | 2 | 3 | 1 20 K. | 30 K | INILI - Columns Rows | 1 | 2 | 3 | 10 W 2 KW 3K INIL Columns Rows | 1 | 2 | 3 | 10 W 1 2 KW 1 3 KI INIL Columns Rows | 1 | 2 | 3 | 1| W | EPI 2 kW 01 3 K | O NILI

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago