Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

MEMORY GAME-

FLIPPING TILES
MEMBER
S

S.NO. REGISTRATION NO. STUDENT’S NAME DEPARTMENT

5. RA221100 30 30 171 KIRTI SINGHAL CSE CORE

1. RA221100 30 30 137 AKANKSHA ANAND CSE CORE

3. RA221100 30 30 152 RITTIKA MITRA CSE CORE

4. RA221100 30 30 16 5 AVISHI MITTAL CSE CORE


INTRODUCTION

● The provided P ython code implements a memory game using an SQLite database.
This memory game challenges the player to find matching pairs of t iles on a game
board. The code manages the game's logic, including shuffling t iles, t racking t ile flips, and
determining when pairs are matched. SQLite is used to store the state of the
game, and the player interacts with the game through the console.
OBJECTIV
E

1.Educational P urpose: To educate individu als, students, or professionals about the features, benefits,
and effective use of the LinkedIn app as a professional networking tool.
2.Skill Develop m ent: To help individu als develop essential skills for creating and m anaging a
professional online presence, including optim izing their LinkedIn profiles,
networking, and personal branding.
3.Career Develop m ent: To assist job seekers in using the LinkedIn app as an effective platform for job
searching, connecting with potential em ployers, and exploring career
opportunities.
4. Entrepreneurship: To guide aspiring entrepreneurs on how to lever age LinkedIn for
building a business network, prom oting their startups, and seeking investm ent opportunities.
WORKING
OF THE
CODE

1.It imports the 'sqlite3 module for working with SQLite databases
and the 'random module for shuffling the t iles. 6. The main() function in it ializes variables to keep t rack of
the number of pairs found and the number of attempts made. It enters
2. The code establishes a connection to an SQL0te database a loop that continues until all 8 pairs are found.
named memory_game.db and creates a cursor for executing SQL
commands on the database. 7.Inside the loop, the current state of the game board is displayed
using the display_board() function.
3. It defines a table named t iles' with three columns: id (an
in teger primary key), 'value (to store the letter associated with 8.The player is prompted to enter two t ile numbers (1-16) to flip. The
each t ile), and flipped (an in teger to indicate if the t ile has been code handles in valid inputs and continues to prompt until valid t ile
flipped, with a default value of o). numbers are entered.

4.The game in it ializes an array t iles containing pairs of letters from 9.It retrieves information about the selected t iles from the database,
'A’ to 'H (for a total of 16 t iles), shuffles them randomly, including their IDs, values, and whether they are already flipped.
and
inserts them into the tiles' table in the database. Each tile is assigned 10.If the selected t iles form a valid match (i.e., they have the same
a unique ID. value and both are not already flipped), the code
updates the 'flipped' column in the database to indicate that these t
5. The 'display_board()' function retrieves the current state of iles have been flipped, increments the 'pairs_found' count, and prints
the t iles from the database and displays them. Flipped t iles are shown a "Match found!" message.
with their values, and unflipped t iles are displayed as
question marks. The board is displayed in a 4x4 grid.
WORKING
OF THE
CODE

-11. If the selected tiles do not form a match, a "No match. Try again." message is displayed.

12. The attempts counter is incremented with each turn.

13. The game loop continues until all 8 pairs are found, at which point it displays a congratulatory message along with the n umb er
attempts made to complete the game. of

14. Finally, the database connection is closed.


OVERVIE
W
5. Main Game Loop: - The main () function manages the game loop,
1. Database Initialization: - It begins by importing the
where the player attempts to find pairs of matching tiles.
necessary libraries, sqlite3 for database in teraction and
- It keeps track of the number of pairs found and the total number
random for shuffling t iles. - Initializes an SQLite
of attempts.
database named "memory_game.db" and creates a table called "t
6. P layer Input: - Asks the player to enter the numbers of two t iles to
iles" to store the state of each t ile. Each t ile has an ID, a textual
flip (e.g., 1-16) in each turn. - Validates the input to
value (like letters), and a "flipped" status.
ensure it 's a valid number.
2. Game Setup: - Generates a list of t iles with pairs of values (in
7. Checking for Matches: - Retrieves the t iles from the
this case, letters from 'A' to 'H') and shuffles them randomly
database based on the player's input and checks if they form a valid
to create the in it ial game board.
match. - If a valid match is found (same value, both t iles are
face-down), it updates the database to mark them as flipped
3. Inserting Tiles: - Inserts the shuffled t iles in to the
and increments the pairs found counter. - If no match is found, it
database table, in it ializing them with a "flipped" status of 0
informs the player to try again.
(indicating that all t iles are in it ially face-down).
8.Game Completion: - Continues the game loop until the player has
4. Display Board: - Defines a function display_board() to print the
found all eight pairs of t iles. - Once all pairs are found, it displays
current state of the game board, showing
a congratulatory message along with the number of attempts made.
flipped t iles with their values and face-down t iles with
9.Database Closing: - Finally, the code closes the SQLite database
question marks.
connection.
CONCLUSIO
N
In summary, this code implements a basic memory game where the player
must find matching pairs of tiles by flipping them over. It utilizes an
SQLite database to manage the state of the game board and allows
interaction through the console.

You might also like