Skip to content

Instantly share code, notes, and snippets.

@ambethia
Last active December 11, 2016 20:50
Show Gist options
  • Select an option

  • Save ambethia/e9bd1760f78fe36dcd7e03a1c2a4edc1 to your computer and use it in GitHub Desktop.

Select an option

Save ambethia/e9bd1760f78fe36dcd7e03a1c2a4edc1 to your computer and use it in GitHub Desktop.
Pseudocode to describe a game of memory.
faces = [πŸ€–, 🐒, 🐼, πŸ™, πŸ‘Ύ, πŸ‘Ή, 🐒, πŸ‘Ύ, 😱, πŸ€–, 🐲, πŸ™, 😱, πŸ‘Ή, 🐼, 🐲]
matched = []
picks = []
choose(positionOfCard) function:
If the number of picks is 2:
Do nothing (stop the player from choosing 3 cards).
Add positionOfCard to picks.
If the number of picks is now 2:
check()
check() function:
If faces[picks[0]] is equal to faces[picks[1]]:
Add positionOfCard to matched.
If all matches found (i.e. matched is the same length as faces):
Game over.
Empty picks after a short delay.
render() function:
For each card in faces:
When the card is clicked: choose(positionOfCard)
If picks inclues positionOfCard:
Show card face (faces[positionOfCard]).
Else:
Show card back.
If matched includes card:
Your Choice: Show Card face or do not show card (i.e. It has been removed from the board).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment