This is my excersise and solution, tryin to find out if its good or not if not make changes and expl

In the game of memory the user is given a set of face down cards from which he then picks a pair. If the value of the pairs are equal the pair is removed from play and the process repeated no more card pairs remain. The game may be played with both even and odd numbers of cards. With an odd number of cards, one unmatched card remains.
Write pseudocode for a program which simulates the memory game. Your program should give 2.5 n chances to match all the cards. Your program should allow the user to select n, the total number of cards, as either 8, 17, 32 or 51.
At the end of play your program should output whether a player won or lost. If the player won it should output the total number of turns which the player took.

My solution

Set the number of cards in play to 0.

While the number of cards is not equal to 8, 17, 32 or 51:
If the number of cards is not equal to zero:
Prompt the user to choose the number of cards. Tell the user than they can only choose 8, 17, 32 or 51.
Store user's choice as the number of cards in play.
Else:
Prompt the user to choose the number of cards between 8, 17, 32 or 51.
Store user's choice as the number of cards in play.

Set number of chances to 2.5 times the number of cards.

Create area for first card chosen to be stored.
Create area for second card chosen to be stored.

Display cards in a grid according to the number of cards.

While the cards in play is greater than 1 and the number of chances is greater than 0:
If any card store is empty:
Prompt the user to pick a card.
If the first card store is empty:
Store card type as first card.
Else:
Store card type as second card.
Display chosen card to the user.
Decrease the number of chances by 1.

Else If second card type is equal to first card type:
Tell the user that the cards are a match.
Remove both cards from play (remove from display).
Delete both card types from store.
Reduce number of cards in play by 2.

Else:
Tell the user that the cards do not match.
Hide (flip over) both cards from the user.
Delete both card types from store.

If the number of chances is equal to 0:
Tell the user that they have lost.
Else:
Tell the user that they have won.
Sign In or Register to comment.