This is a Java Swing-based implementation of the popular 2048 puzzle game. The game uses keyboard controls to slide and combine numbered tiles to reach the number 2048.
- Classic 2048 gameplay
- Smooth tile movement and merging logic
- Color-coded tiles
- Keeps track of current and best scores
- Win (2048) and Game Over detection
- Option to restart the game using the
Rkey
- Java Development Kit (JDK) 8 or later
- Any Java IDE (e.g., IntelliJ IDEA, Eclipse) or terminal to compile and run
-
Click the Download ZIP link or clone the repo:
[git clone https://github.com/AlbinMath/2048-in-java.git] cd 2048-in-java -
Compile:
javac Game2048.java
-
Run:
java Game2048
- Open the
.javafile in your favorite Java IDE. - Compile and run the
Game2048.javafile. - Use arrow keys to play.
| Key | Action |
|---|---|
| Arrow Keys | Move tiles |
R |
Restart game |
Esc |
Exit game |
.
โโโ Game2048.java # Main Java source file
โโโ README.md # This file
โโโ screenshot.png # Optional screenshot
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ๐ using Java and Swing.
To use this project in your GitHub repository:
-
Create a new GitHub repository (if you haven't already).
-
Add this project to your GitHub repo:
git init git remote add origin https://github.com/yourusername/2048-java-swing.git git add . git commit -m "Initial commit - 2048 Java Game" git push -u origin main
-
If you're using SSH key authentication, make sure your key is added to GitHub:
- Generate key (if you haven't):
ssh-keygen -t ed25519 -C "your_email@example.com" - Add it to the ssh-agent:
eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
- Copy the key and add it to GitHub under Settings > SSH and GPG keys:
cat ~/.ssh/id_ed25519.pub
- Generate key (if you haven't):
-
Then, push using SSH:
git remote set-url origin git@github.com:yourusername/2048-java-swing.git git push -u origin main
โ This makes it easy to collaborate, track changes, and share your 2048 game project publicly or privately using GitHub.
"# 2048-in-java"
