Divash Project
Divash Project
ON
PYTHON BASED
2048 GAME
SUBMITTED BY:-
SOLITAIRE INFOSYS
Mohali: C-110, Industrial Area Phase-VII, Mohali, India.
DECLARATION
I am a student of Computer ENGG. Diploma, session: 2021- 2024
in your college. We hereby declare that the work presented in this
Project is the outcome of our own bona fide work and is correct
to the best of our knowledge and this work has been undertaken
taking care of Engineering Ethics. It contains no material
previously published or written by another person nor material
which has been accepted for the award of any other degree or
diploma of the university or other institute of higher learning,
except where due acknowledgment has been made in the text.
Solitaire Infosys Pvt. Ltd. is an acclaimed IT service provider contributing its part in
the development of many businesses around the globe. They socialize with their
clients to get a superior cognizance of their business and requirements and helpthem
in fabricating websites and applications for their business. The company was founded
in 2011 by a dynamic duo with the same aim and zeal; they have come a long way in
satisfying our clients. They are serving their clients with the world- class services for
more than seven years now.
With every project that they deliver, they deliver their respect, creativity, quality,
transparency, and teamwork to their clients. They have the experience, expertise, and
capabilities to enable organizations to accelerate their service processes in every
possible way. They are known for their excellent customer satisfaction, cost-
effectiveness, and innovative skills that are unparalleled.
VISION
They visualize becoming the most trusted and respected IT service provider across
the globe with their vibrant, dynamic, and value-based IT solutions that revolve
around their clients, team, and international standards. Solitaire Infosys Pvt. Ltd.
envisions becoming a reliable partner to all its clients and focusing on doing
everything ethically and rightly. They are always open to accept their mistakes and
have the nerve to do the necessary changes.
CONTENT
1. Declaration
2. Certificate
3. Acknowledgement
4. Abstract
5. Introduction to Company
6. Introduction to Project
7. Program Description
8. Interaction Diagram
9.Project Implementation
10.Project Benefits
11.Project Architecture
12.Conclusion
INTRODUCTION TO PROJECT
1. Importing Libraries:-
➢ from tkinter import *: Imports the tkinter library, which
is used to create the GUI for the game.
➢ from tkinter import messagebox: Imports the
messagebox module from tkinter to display messages in
pop-up windows.
➢ import random: Imports the random module for
generating random numbers.
2. Class Board:-
➢ This class represents the game board and contains
methods for managing the game grid and GUI elements.
➢ It initializes the Tkinter window, sets its title, and creates
a grid for the game board.
➢ The bg_color and color dictionaries store background and
text color codes for different tile values.
➢ The init method sets up the initial state of the game
board.
3.Class Methods:-
➢ reverse(): Reverses the rows of the game grid.
➢ transpose(): Transposes the game grid (switches rows
and columns).
➢ CompressGrid (): Compresses the grid by moving non-
zero elements to the left.
PROJECT EMPLEMENTATION
This is a Python program that implements the game 2048 using the
Tkinter library for the graphical user interface (GUI). The program is
divided into two main classes: Board and Game.
1. Board Class:
• This class defines the graphical interface of the game.
The main part of the program at the end creates an instance of the
Board class (gamepanel) and an instance of the Game class
(game2048). It then starts the game by calling the start method of
the Game class.
The program provides a basic implementation of the 2048 game,
allowing the player to play using arrow keys and displaying messages
when the game is won or lost. The game board is represented visually
using Tkinter's labels, and the game logic is implemented within the
Game class.
PROJECT BENEFITS
game grid.
• board: A 2D list of Label widgets representing the game
cells.
• gridCell: A 2D list representing the game state.
• Methods:
• __init (): Initializes the game board and creates the grid
of cells.
• reverse(): Reverses the rows of the grid.
empty cells.
• mergeGrid(): Merges cells with the same values.
• random_cell(): Generates a random "2" tile in an empty
cell.
• can_merge(): Checks if there are any possible merges.
• paintGrid(): Updates the GUI to reflect the current game
state.
Game Class:
• This class controls the game logic and user interactions.
• Attributes:
• Methods:
events.
• link_keys(event): Handles user key events (Up, Down,
state.
• It starts the game by calling the start method of the Game class.
• The player interacts with the game using arrow keys, and the
game logic is handled by the Game class.
• Messages are displayed in message boxes when the player wins
or loses.
4. Data Structures:
• Lists and dictionaries are used to represent the game board and
5. Game Logic:
• Game logic, such as merging tiles, generating new tiles,
6. User Interface:
• Tkinter is used to create a simple and user-friendly interface for
the game.
• Labels are used to display the numbers on the game board, and