The 2048 Puzzle Game is a modern implementation of the classic sliding tile game where players combine numbers to reach the coveted 2048 tile. Developed using Java and JavaFX, this project showcases the integration of graphical interfaces and logical gameplay mechanics, providing an engaging and interactive experience.
Welcome to the 2048 Puzzle Game! This is a Java-based implementation of the classic sliding puzzle game, enhanced with a graphical user interface using JavaFX.
2048-Puzzle-Game/
├── src/ # Source files
│ ├── Gui2048.java
│ ├── Board.java
│ ├── Constants2048.java
├── lib/ # Libraries and dependencies
│ ├── javafx/ # JavaFX JARs
│ │ ├── javafx.base.jar
│ │ ├── javafx.controls.jar
│ │ ├── ...
│ ├── natives/ # Native files (optional)
│ │ ├── libdecora_sse.dylib
│ │ ├── libfxplugins.dylib
│ │ ├── ...
├── dist/ # Packaged JAR file (generated during packaging)
│ ├── 2048.jar
├── run.sh # Script for Linux/macOS
├── run.bat # Script for Windows
├── README.md # Project instructions (this file)
To run the game, you need:
-
Java Runtime Environment (JRE):
- Version: 17 or higher
- Download Java
-
JavaFX Libraries:
- Already included in the
lib/javafx
folder.
- Already included in the
-
Windows:
- Double-click
run.bat
. - Or, open a terminal and run:
run.bat
- Double-click
-
Linux/macOS:
- Open a terminal and run:
./run.sh
- Open a terminal and run:
- Open a terminal or command prompt.
- Navigate to the project directory.
- Run the following command:
java --module-path lib/javafx --add-modules javafx.controls,javafx.fxml -jar dist/2048.jar
- Interactive GUI: Built with JavaFX, the game includes a responsive grid and smooth animations.
- Save and Load Boards: Save your progress and continue later.
- Dynamic Resizing: The game adjusts for larger board sizes.
- Customizable Colors: Tile colors change dynamically based on their value.
- Use arrow keys to move tiles:
- Up, Down, Left, Right.
- Combine tiles with the same value to merge them (e.g.,
2 + 2 = 4
). - Reach the
2048
tile to win the game! - Game ends when no moves are possible.
This project is packaged as an executable JAR. It can also be built into platform-specific executables using tools like jpackage
.
To package for your platform:
jpackage --input dist --name 2048PuzzleGame --main-class Gui2048 --main-jar dist/2048.jar \
--module-path lib/javafx --add-modules javafx.controls,javafx.fxml --output dist
-
Error: Unable to find JavaFX runtime: Ensure you include the JavaFX libraries using the
--module-path
and--add-modules
flags. -
Error: Unsupported Java Version: Verify you have Java 17 or higher installed.
This project is licensed under the MIT License. Feel free to use and modify the code.
- Christine Wu