Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/manavalan2517/memory-game-python


https://github.com/manavalan2517/memory-game-python

memory-game memory-game-python py python

Last synced: 27 days ago
JSON representation

Awesome Lists containing this project

README

        

###

# Memory Game Python Script Breakdown

## 1. Importing Necessary Modules
- **random**: for generating random numbers.
- **tabulate**: for formatting the grid display.
- **os**: for clearing the console.

## 2. Defining Global Variables
- **values**: a dictionary mapping letters to their corresponding indices in the grid.
- **temp_found**: a list to store the numbers temporarily found during each turn.
- **user_values**: a list to store the user's input for each turn.
- **user_choices**: a list to keep track of the tiles already uncovered by the user.
- **progress**: a boolean flag to indicate whether the game is still in progress.
- **competed**: a boolean flag to indicate whether the game has been completed.

## 3. Taking User Input for the Grid Size
- The user is prompted to enter a choice for the grid size (e.g., 2 for a 2x2 grid, 4 for a 4x4 grid).
- The input is validated to ensure it is an even number.

## 4. Defining Functions
- **game_elements(num)**: a function that generates the grid elements. It creates a list of random numbers and shuffles them to create pairs.
- **game_process(num)**: a function that handles the game logic. It displays the grid, prompts the user for input, and updates the grid based on the user's choices. It also checks for matches and updates the game status accordingly.

## 5. The Main Game Loop
- The main list is populated with the grid elements using the `game_elements` function.
- The `game_process` function is called to start the game.
- After each game, the user is prompted to choose whether to play again.
- If the user chooses to quit, the loop breaks.

**Overall, the selected code provides a complete implementation of the memory game with user interaction and grid display.**

###