Sokoban is a classic puzzle game where the player controls a character who must push boxes to designated storage locations. The goal is to complete each level by strategically moving the boxes without getting stuck or blocking critical paths.
This project is a Java implementation of the Sokoban game, featuring a graphical user interface and various game mechanics.
The project follows a MVC architecture, that is organized into several packages:
- es.upm.pproject.sokoban: Main package containing the Sokoban class, which serves as the entry point for the game.
- es.upm.pproject.sokoban.controller: Contains the game controller implementation (ControllerImpl) responsible for managing the game's logic.
- es.upm.pproject.sokoban.model: Includes the implementations for the game models (GameModelImpl, MapModelImpl, MovementModelImpl), representing the game state and movements.
- es.upm.pproject.sokoban.view: Contains the implementation of the graphical user interface (ViewImpl) and menu (MenuViewImpl) using Java Swing.
This architecture is introduced in a Maven project for testing and dependencies management.
- Java: recommended 11, works 17.
- Maven: recommended 3.9.6.
- Open the project in your preferred Java IDE.
- Locate the Sokoban class in the es.upm.pproject.sokoban package.
- Run the main method within the Sokoban class.
Using Maven:
- Go to the sokoban folder
- Compiles the project:
mvn compile
- Run the program:
mvn exec:java
The menu provides various options for managing the game, including starting a new game, saving, loading, restarting, undoing moves, and closing the game.
The game loads all .txt file that exist in levelFiles/
. More levels can be added, and must follow this format:
- The first line contains the name of the level.
- The second line contains the elements of the board, nRows and nColumns of the board.
- The following nRows lines contains the elements of the board. Each row must contain nColumns with:
- +: Wall
- .: Empty square
- *: Goal Position
- #: Box
- W: Warehouse man
- At least 1 box and 1 goal position.
- Only 1 warehouse man
- The board must contain the same number of boxes and goal positions.
The application will show if the level doesn't follow this rules
Contributions to the Sokoban project are welcome! If you find any issues or have suggestions for improvements, please create an issue or submit a pull request.