CPE Main Report
CPE Main Report
ON
Game:2048 Puzzle Game
SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS
DIPLOMA IN
INFORMATION TECHNOLOGY
SUBMITTED TO :-
Submitted by: -
Sr. No Name Enrollment Number Seat Number
CERTIFICATE
Date:
Place: Solapur
Acknowledgement
We would like to express our sincere gratitude to all those who have contributed to the
successful completion of the Game:2048 Puzzle Game
We are deeply appreciative of the guidance and support provided by our project guide
Prof. Gaikwad S. N., whose expertise and insights have been invaluable in shaping the
direction of our project. We are also grateful to our principal, Dr. Ashok Upadhyay, for their
encouragement and support throughout the project's duration.
We extend our appreciation to the team members who worked tirelessly to bring this
project to fruition, collaborating effectively and contributing their diverse skills and
expertise.
We would like to acknowledge the farmers, industry experts, and stakeholders who
participated in interviews, surveys, and workshops, providing valuable feedback and insights
that informed the development of the web application.
Special thanks to Government Polytechnic, Solapur for providing resources, facilities, and
support for the execution of this project.
Lastly, we express our gratitude to our families, friends, and loved ones for their
unwavering support, patience, and understanding during the challenging moments of this
project.
ABSTRACT
This project presents the development of a 2048 game, a sliding block puzzle that challenges
players to combine tiles with identical numbers on a 4x4 grid, aiming to achieve a tile with
the number 2048. The game is renowned for its simplicity and depth, offering a rich case
study in algorithm efficiency, user interface (UI) design, and the implementation of user
experience (UX) principles in game development. The primary objectives of this project
include the creation of an intuitive and responsive UI, the development of efficient
algorithms for game logic, and the exploration of enhancements to increase user engagement.
A significant focus is placed on UI/UX design, aiming to create a visually appealing and
intuitive interface that enhances player engagement without compromising the game's
minimalist aesthetic. This includes the implementation of smooth animations, coherent color
schemes, and responsive design principles.
This 2048 game project is expected to serve as a foundation for future projects in game
development, offering insights into the balance between functionality and aesthetic appeal,
the importance of algorithm efficiency, and the role of user feedback in iterative
design processes.
Index
4 Methodology
5 Details of designs
- I/O design
- UI design
-1 ER Diagram
-.2 setup Design
6 Details of working
7 Details of processes
8 Coding
8.1 Languages /tools used
8.2 Justification for Selection of languages /tools
8.3 Important Modules
8 Results and application
9 Conclusion
10 Appendix
11 References
Introduction
Welcome to the realm of "2048," where the intersection of mathematics, strategy, and
addictive gameplay creates a captivating experience. This capstone project aims to delve deep
into the dynamics of the 2048 game, a digital puzzle that has taken the gaming world by
storm.
2048 is sliding block puzzle game developed by Gabriele Cirulli. It’s a game played on a 4x4
grid with tiles numbered 2n where ‘n’ represents a natural number. The objective of the game
is to combine tiles of the same number to eventually form the number 2048. The user can
move in the four cardinal directions and after every move a new tile is generated randomly in
the grid which is either numbered 2 or 4 with a probability of about .10. A move is legal if at
least one tile can be slid into an empty spot or if the tiles can be combined in the chosen
direction. The game ends when the user does not have any legal moves left. One cannot help
but ask the question, since the game is based on mathematics, whether moves can be
optimised to improve our score by applying different concepts of mathematics.
As you explore this capstone project, you will embark on a journey to uncover the inner
workings "2048." We will examine the game's rules, strategies for success, and even consider
its educational applications. Through this project, we hope to gain a deeper appreciation for
the intricate balance of simplicity and complexity that "2048" offers
1
Literature Survey
A literature survey on the "2048" game can encompass various aspects, including its
history,gameplay, mathematical analysis, educational potential, and social impact. Here's a
brief overview:
- Explore the origins and development of the game, including the original "2048" by
Gabriele Cirulli and its variants. -
-Investigate how the game gained popularity and its impact on the mobile gaming industry
- Describe the fundamental rules of the game, such as merging tiles and achieving higher
numbered tiles. -
-Analyze the strategies and tactics players use to maximize their scores and reach the 2048
tile.
3. *Mathematical Analysis*:
- Discuss the mathematical principles underlying the game, including powers of 2 and
probability. -
-Explore algorithms and heuristics used to optimize gameplay, such as the Monte Carlo Tree
Search (MCTS) algorithm.
4. *Educational Applications*:
- Investigate how "2048" can be used as an educational tool for teaching math,
problemsolving, and logical thinking. -
-Examine case studies and research on the use of "2048" in educational settings.
2
5. *Cognitive and Psychological Aspects*:
- Analyze the cognitive skills and psychological aspects involved in playing "2048," such
as pattern recognition, decision-making, and perseverance.
- Explore the social phenomenon around the game, including its influence on pop culture,
social media challenges, and community engagement. -
Discuss the addictive nature of "2048" and its impact on player behavior.
- Review different versions and adaptations of the game, including larger grids, new rules,
and multiplayer variations.
-Discuss the implications of these adaptations on gameplay and player engagement.
- Identify gaps in the existing literature and suggest potential areas for future research, such
as AI-based gameplay, gamification in education, and neuroscientific studies of player
behavior.
A literature survey on "2048" should encompass a wide range of sources, from academi
papers and articles to online forums and community discussions, to provide a comprehensive
understanding of the game's multifaceted nature and its significance in the world of gaming
and education.
3
Scope of the project
The scope of developing a 2048 game encompasses several key areas, highlighting its
multifaceted potential not just as a game but as a project that touches on various aspects of
programming, design, and user experience. Here are the main components:
- *Core Mechanics:* Implementing the basic gameplay mechanics, including tile movements,
combination of tiles, and the spawning of new tiles after each move.
- *Efficiency Optimization:* Developing algorithms for the game logic that are both efficient
and scalable, ensuring smooth gameplay across different devices and platforms.
- *Advanced Features:* Adding functionality such as undo moves, save/load game state, and
possibly implementing AI to suggest the next move or play the game autonomously.
- *Design Principles:* Creating an intuitive and appealing interface that enhances user
engagement without overwhelming the minimalist aesthetic of the game.
- *Responsiveness:* Ensuring the game is playable on various devices and screen sizes,
maintaining a consistent and enjoyable experience.
- *Accessibility:* Implementing features that make the game accessible to a wider range of
players, including those with disabilities.
3. *Technology Integration:*
4
- *Use of Libraries/Frameworks:* Leveraging existing libraries or frameworks to speed up
development time and focus on unique aspects of the game.
- *Functionality Testing:* Ensuring the game works as intended across all targeted platforms
and devices.
- *Performance Optimization:* Testing and optimizing the game to run smoothly, minimizing
lag and ensuring responsive controls.
- *User Testing:* Gathering feedback from users to refine gameplay, UI/UX, and address any
issues.
6. *Educational Value:*
- *Learning Tool:* Using the game development process as a learning tool for programming
concepts, design principles, and project management.
5
Methodology
3. *Develop a Strategy*:
- Create a strategic approach to guide your decisions. Consider factors like prioritizing the
largest tile, maintaining order on the grid, and planning ahead.
4.*Pattern Recognition*:
- Train your ability to recognize common tile patterns that can lead to successful mergers. For
example, understanding the "snake pattern."
6. *Long-Term Planning*:
- Plan not only for the current move but also for future moves. Avoid moves that may block
potential future mergers.
6
Designs
• *User Interface:*
• 1. *Grid Layout*: The game should feature a 4x4 grid to hold the tiles. The grid should be
visually distinct and easy to navigate.
• 2. *Tile Design*: Each tile should be a square with a number representing its value. Start
with two tiles (e.g., two "2" tiles) on the grid at the beginning.
• 3. *Score Display*: Display the player's score prominently on the screen, updating in real-
time as tiles merge.
• 4. *New Game Button*: Include a button that allows the player to start a new game when
desired.
• 5. *Undo Button*: Offer an "undo" button to allow the player to revert to the previous move.
• 6. *Settings and Options*: Provide options to adjust game settings, such as toggling sound
effects, enabling/disabling hints, or changing the grid size for variations.
7
• *Game Mechanics:*
• 1. *Tile Movement*: Tiles can be moved in four directions: up, down, left, and right.
• 2. *Tile Merging*: When two tiles of the same value are moved into each other, they merge
into a single tile with a value that's the sum of the two merged tiles.
• 4. *Lose Condition*: The game ends when no more valid moves can be made.
• 5. *Random Tile Generation*: New tiles (e.g., "2" or "4" tiles) should appear on the grid
after each move, ideally in a random open space
• *Visual Style:*
• 1. *Color Palette*: Use a pleasing color palette for tiles and the background. Different tile
values can be represented with distinct colors.
• 2. *Animations*: Add subtle animations to make tile movements and merging visually
appealing.
• 3. *Responsive Design*: Ensure that the game interface is responsive and works well on
various screen sizes and orientations
. • *Accessibility:*
• 1. *Text Labels*: Use clear text labels and consider providing alternative text for images and
icons for accessibility.
8
.
Procedure:
Creating a "2048" game involves multiple steps in the development process. Here's a
tentative procedure to guide you through building the game:
- Choose a programming language and development framework (e.g., advance java and Java
for web-based games).
- Create the game grid, tiles, and user interface elements according to your design.
- Implement the core game logic, including tile movement, merging, and random tile
generation. - Develop the scoring system and win/lose condition checks.
- Incorporate sound effects, animations, and other visual elements to enhance the gaming
experience.
- Test the game thoroughly to ensure all mechanics work as intended.
- Implement the user interface components, including the score display, new game button,
undo button, and settings/options menu.
- Ensure the interface is responsive and user-friendly on various devices and screen sizes
-Perform extensive testing to identify and fix any bugs, glitches, or unintended behaviors.
- Test the game on different browsers and devices to ensure compatibility.
*5. Playtesting:*
- Involve playtesters to gather feedback on gameplay, user experience, and difficulty level.
9
- Use this feedback to make necessary adjustments to game mechanics, balance, and user
interface.
*6. Optimization:*
- Optimize the game's code and assets for performance and load times. - Implement strategies
to minimize memory usage and reduce lag.
*7. Accessibility:*
- Ensure that the game is accessible to players with disabilities, including screen reader support
and keyboard navigation.
*8. Deployment:*
- Choose the platforms and app stores where you want to release the game (e.g., Google Play
Store, Apple App Store, or a website). - Follow platform-specific guidelines for submission
and approval.
- Plan a marketing strategy to promote the game, including creating promotional materials and
utilizing social media channels.
10
1 ER Diagram:
11
2 Setup Design:
12
13
Working
Working:
1. *Movement*: Players swipe (up, down, left, or right) to move the tiles on the grid. When
two tiles with the same number touch, they merge into one tile whose value is the sum of the
two original tiles.
1. *Objective*:
The goal is to combine tiles until you create a tile with the number 2048. However, you
can continue to play beyond this point to achieve higher scores.
2. *Scoring*:
Every time two tiles merge, the player earns points equal to the value of the new tile. For
example, merging two tiles of value 4 will give you an 8-point score increase.
4. *Gameplay*:
- After every swipe, a new tile (either a 2 or a 4) randomly appears in an empty spot on the
board.
- The player needs to strategize their swipes to avoid filling up the board. If the board fills
up and no adjacent tiles can be combined (i.e., there are no possible moves left), the game ends.
5. *Strategy*:
- A common strategy is to try to keep the highest value tile in a corner and work to
continuously combine other tiles into it.
- Planning moves ahead and trying to maintain some empty spaces on the grid for as long as
possible are key strategic elements.
14
Processes
Process:
1.Requirement Gathering:
-Conduct interviews, surveys, and workshops with gamers to understand their needs and
key points.
-Identify key features and functionalities required to address these needs effectively.
15
Coding
package JustDoIt;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.RoundRectangle2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
int boardWidth = 6;
int boardHeight = 6;
int x = 8;
int y = 8;
int xa;
int ya;
boolean win;
boolean lost;
boolean move;
boolean pressed;
boolean up;
boolean down;
boolean left;
boolean right;
16
Color c2 = new Color(0, 0, 0);
Font font = new Font("Ariel", Font.BOLD, 0);
public Main() {
this.addMouseListener(this);
}
17
for(int i = 0; i<boardWidth; i++) {
for(int j = 0; j<boardHeight; j++) {
if(Math.random() > 0.99 && sit[i][j] == 0) {
isCreated = true;
sit[i][j] = 2;
break;
}
}
if(isCreated)
break;
}
if(isCreated == false)
randomNumber();
}
18
}
else if(left) {
if(j != 0) {
if(sit[i][j-1] != 0) {
if(sit[i][j-1] == sit[i][j] && con[i][j] != 1 && con[i][j-1] != 1) {
sit[i][j-1] += sit[i][j];
sit[i][j] = 0;
con[i][j-1] = 1;
activity++;
}
}
else {
sit[i][j-1] = sit[i][j];
sit[i][j] = 0;
if(con[i][j] == 1) {
con[i][j-1] = con[i][j];
con[i][j] = 0;
}
activity++;
}
}
}
else if(up) {
if(i != 0) {
if(sit[i-1][j] != 0) {
if(sit[i-1][j] == sit[i][j] && con[i][j] != 1 && con[i-1][j] != 1) {
sit[i-1][j] += sit[i][j];
sit[i][j] = 0;
con[i-1][j] = 1;
activity++;
}
}
else {
sit[i-1][j] = sit[i][j];
sit[i][j] = 0;
if(con[i][j] == 1) {
con[i-1][j] = con[i][j];
con[i][j] = 0;
}
activity++;
19
}
}
}
else if(down) {
if(i != boardWidth-1) {
if(sit[i+1][j] != 0) {
if(sit[i+1][j] == sit[i][j] && con[i][j] != 1 && con[i+1][j] != 1) {
sit[i+1][j] += sit[i][j];
sit[i][j] = 0;
con[i+1][j] = 1;
activity++;
}
}
else {
sit[i+1][j] = sit[i][j];
sit[i][j] = 0;
if(con[i][j] == 1) {
con[i+1][j] = con[i][j];
con[i][j] = 0;
}
activity++;
}
}
}
}
}
}
if(activity == 0) {
move = false;
randomNumber();
}
}
20
}
if(sit[i][j] == 0)
op++;
if(j != boardHeight-1 && i != boardWidth-1 && j != 0 && i != 0) {
if(sit[i][j] == sit[i][j+1] || sit[i][j] == sit[i][j-1] || sit[i][j] == sit[i+1][j] || sit[i][j]
== sit[i-1][j] || sit[i][j] == 0) {
op++;
}
else if(j == 0 || j == boardHeight-1){
if(!(i == 0 && j == 0)) {
if(!(i == 0 && j == boardHeight-1)) {
if(sit[i][j] == 0 || sit[i][j] == sit[i+1][j] || sit[i][j] == sit[i-1][j]) {
op++;
}
}
}
}
else if(i == 0 || i == boardWidth-1){
if(!(i == boardWidth-1 && j == 0)) {
if(!(i == boardWidth-1 && j == boardHeight-1)) {
if(sit[i][j] == 0 || sit[i][j] == sit[i][j+1] || sit[i][j] == sit[i][j-1]) {
op++;
}
}
}
}
}
}
}catch(Exception e) {}
if(op == 0) {
lost = true;
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
21
Graphics2D g2d = (Graphics2D)g;
g2d.setColor(Color.GRAY);
g2d.fillRect(0, 0, getWidth(), getHeight());
22
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/4);
break;
case 128:
c = new Color(255, 193, 37);
c2 = new Color(0, 0, 0);
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/3);
break;
case 256:
c = new Color(238, 180, 34);
c2 = new Color(0, 0, 0);
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/3);
break;
case 512:
c = new Color(238, 173, 14);
c2 = new Color(0, 0, 0);
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/3);
break;
case 1024:
c = new Color(238, 173, 14);
c2 = new Color(0, 0, 0);
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/2);
break;
case 2048:
c = new Color(205, 149, 12);
c2 = new Color(0, 0, 0);
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/2);
break;
case 4096:
c = new Color(0, 0, 0);
c2 = new Color(255, 255, 255);
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/2);
break;
default:
23
c = new Color(255, 0, 0);
c2 = new Color(255, 255, 255);
font = new Font("Ariel", Font.BOLD, (int)board[i][j].getWidth() -
(int)board[i][j].getWidth()/2);
break;
}
g2d.setColor(c);
g2d.fill(board[i][j]);
g2d.setColor(Color.GRAY);
g2d.draw(board[i][j]);
if(sit[i][j] != 0) {
g2d.setColor(c2);
g2d.setFont(font);
if(sit[i][j] < 128)
g2d.drawString(Integer.toString(sit[i][j]), (int)board[i][j].getX() +
(int)board[i][j].getWidth()/4, (int)board[i][j].getY() + (int)board[i][j].getHeight() - 10);
else {
g2d.drawString(Integer.toString(sit[i][j]), (int)board[i][j].getX() +
(int)board[i][j].getWidth()/8, (int)board[i][j].getY() + (int)board[i][j].getHeight() - 15);
}
}
}
}
Font font = new Font("Ariel", Font.BOLD, 100);
g2d.setFont(font);
if(win) {
g2d.setColor(Color.green);
g2d.drawString("YOU WIN!!!", getWidth()/18, getHeight()-getHeight()/2);
}
else if(lost) {
Font font2 = new Font("Ariel", Font.BOLD, 90);
g2d.setFont(font2);
g2d.setColor(Color.red);
g2d.drawString("GAME OVER", getWidth()/150, getHeight()-getHeight()/2);
}
}
@Override
public void mouseClicked(MouseEvent arg0) {
24
// TODO Auto-generated method stub
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
@Override
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
}
@Override
public void mouseReleased(MouseEvent e) {
xa = e.getX() - x;
ya = e.getY() - y;
if(Math.abs(xa) > Math.abs(ya)) {
if(xa > 0) {
right = true;
up = false;
down = false;
left = false;
}
else {
right = false;
up = false;
down = false;
left = true;
}
}
25
else {
if(ya < 0) {
right = false;
up = true;
down = false;
left = false;
}
else {
right = false;
up = false;
down = true;
left = false;
}
}
if(right)
System.out.println("right");
if(left)
System.out.println("left");
if(up)
System.out.println("up");
if(down)
System.out.println("down");
setCon();
move = true;
26
m.setBoard();
while(true) {
m.repaint();
Thread.sleep(15);
m.setBoard();
if(m.move) {
m.moveNumbers();
m.check();
}
if(m.win || m.lost)
break;
}
}
};
27
Output:
28
29
Setup :
30
Results
1. Results
The results or outcomes of the 2048 game can be categorized based on the player's
achievement and strategy. Here's a brief overview:
1. *Winning the Game*: The primary objective is to create a tile with the number 2048.
Achieving this means the player has won the game. However, it's possible to continue playing
beyond this point to accumulate a higher score by creating tiles with even larger numbers,
such as 4096, 8192, and so on.
2. *High Scores*: The game also keeps track of the player's score, which increases with each
combination of tiles. High scores are often pursued by players as a secondary objective to the
main goal of creating a 2048 tile. The score is a measure of how efficiently a player has
combined the tiles and how long they have been able to continue the game after reaching the
2048 tile.
3. *Game Over*: If the player fills up the board with tiles and no more moves are possible
(i.e., no adjacent tiles can be combined), the game ends. The final score is calculated, and the
player can start over to try and achieve a better result.
4. *Strategy and Improvement*: Over time, players develop strategies to maximize their
scores and chances of winning. These can include tactics like keeping the highest-value tiles
in a corner and carefully planning moves to avoid prematurely filling the board.
31
5. *Personal Bests and Competition*: Many players aim to beat their own high scores, while
others compete with friends or on global leaderboards to see how they rank in achieving the
highest possible tile or score.
The allure of 2048 lies in its simple yet challenging gameplay, where each new game offers
a fresh opportunity to beat previous records or achieve new milestones.
Conclusion
In conclusion, the "2048" game is a captivating puzzle that combines simple mechanics with
complex strategic depth. Its evolution from a single-player mobile game to a global
phenomenon has highlighted the inherent appeal of combining numbers and logic. Whether
as a source of entertainment, a tool for teaching mathematical concepts, or a subject of study,
"2048" continues to leave its mark on the gaming landscape, showcasing the enduring allure
of numerical puzzles in our digital age.
32
Conclusion & Future scope
Conclusion:
The 2048 game, since its inception, has remained a popular and engaging puzzle game, cherished for its
simplicity, cognitive challenge, and the quick satisfaction it offers. Its accessibility and short gameplay loops
make it an enduring choice for casual gamers and those seeking a mental workout alike. Here's a look at its
conclusion and the potential future scope:
Conclusion:
- *Enduring Popularity*: 2048 has cemented its place in the realm of popular puzzle games due to its
straightforward mechanics, challenging gameplay, and the addictive satisfaction of achieving a high score or
reaching the elusive 2048 tile and beyond.
- *Cognitive Benefits*: It encourages strategic thinking, planning, and problem-solving, contributing to its
appeal across a wide age range. Players learn to anticipate the consequences of their moves in advance, a
skill that has broader applications outside the game.
- *Community and Sharing*: The game's success has fostered a community of players who share strategies,
high scores, and variations, enhancing its replay value and keeping the interest alive.
33
Future Scope:
- *Technological Integration*: With advancements in mobile technology and app development, 2048 could
see integration with newer technologies like augmented reality (AR) for a more immersive experience or
social media for easier sharing of achievements and competitive play.
- *Educational Applications*: Its potential for cognitive skill development could be harnessed more formally
in educational contexts, perhaps tailored as a tool for learning mathematics or strategic thinking in a fun and
engaging manner.
- *Variations and Expansions*: Developers can create more complex variations of the game, introducing new
rules, grid sizes, or objectives to keep the gameplay fresh. There's also the potential for multiplayer modes,
where players can compete or collaborate in real-time.
In essence, the 2048 game has a solid foundation with significant potential for growth and adaptation. Its
blend of simplicity, challenge, and the cognitive engagement it offers can serve as a platform for educational
tools, technological innovation, and community building in the gaming world. As long as developers and the
community continue to support and evolve the concept, 2048 is likely to remain a staple in the puzzle game
genre for years to come.
34
References
. https://www.umaexports.net/
• https://creately.com/diagram/example/j9sg1w3e1/e-farmer-classic
• https://aussiefoodexport.com/
• https://www.agrifarming.in/top-agriculture-companies-in-india-best-
35