Skip to content

umberto-bianchin/Progetto_Klotski

Repository files navigation

KLOTSKI PUZZLE

Welcome to the Klotski game project. This is a classic sliding block puzzle game that challenges you to move a large red block into a particular escape position. The program is written with Java Swing and uses a database and a solver API hosted on AWS. The project includes the game itself, a test suite, and the documentation. The source code is available on GitHub under the MIT License.

Authors

Badges

MIT License Java Node.js AWS Maven

view - Documentation view - javaDoc

Manual

How we did it

To start writing the code, we first documented the use cases of the project, modeling all the interactions between the user and the entire system. Next, we identified the main architecture as the MVC (Model-View-Controller) pattern. We created the domain model, sketched the system sequence diagram, and prototyped the user interface (UI). Simultaneously, we modeled the database and later implemented it using AWS. We connected to the database locally through the MySQL connector.

We developed the code incrementally, focusing on one task at a time, which was inspired by the use cases. Each task was written on a local machine, and we used the pair programming technique to boost our productivity. We tested each task before pushing it to the GitHub project. Throughout these cycles, we ensured that all the diagrams and documentation were updated to reflect any modifications made to the initial architecture. Additionally, we implemented new diagrams, such as the internal sequence diagram and class diagram.

One of the final tasks involved implementing the next best move using an external solver in our AWS Lambda. We established communication with our system through POST requests containing JSON parameters. Finally, we wrote and performed tests to assess the coverage of our project and identify any potential issues.

Requirements

You will need Java to be installed on your computer in order to run the project, and you have to use JDK 19 or newer versions as it has been developed and tested on that version. You will also need an internet connection.

Installation

Follow these steps:

  1. Open our @GitHub
  2. Click on the green button Code and then on Download ZIP

  1. Go to the download directory and unzip the file
4a. Using Maven from cmd Navigate to the project folder
  cd Download\Progetto_Klotski-master
  mvn package -DskipTests

You can now find the JAR file in the directory named Target as Progetto_Klotski-1.0-jar-with-dependencies.jar, or you can run it throught cmd with

cd target
java -jar Progetto_Kltotski-1.0-jar-with-dependencies.jar
4b. Maven not installed If you don't have maven installed, but the JAVA_HOME system variable already set-up, you can achive the same results with
./mvnw package -DskipTests 
4c. Using Intellij Idea

Open Intellij Idea, go to the File window, then Open and select the project folder. After that, click on the configuration window

Click on Add new configuration, then on Application

Now select the main class and click on Ok on both windows

Eventually, click on the run button

Game rules

You can read the game rules on the Klotski's Wikipedia page

Documentation

Open the documentation

Screenshots

Acknowledgements

  • Klotski Solver

    This excellent NodeJS Klotski solver runs on our AWS Lambda.

    It is called in Solver class thanks to sendPostRequest() method.

  • FlatLaf

    The FlatLaf library helps us achieve a modern look compared to Java Swing.

    Thanks to the setLookAndFeel method we are able to load the look specified by the given class name: FlatDarkLaf (Dark theme)

          UIManager.setLookAndFeel("com.formdev.flatlaf.FlatDarkLaf");
    
  • GitBook

    GitBook helped us create clean and organized documentation for this project.

  • Maven

  • JSON simple

    JSON Simple helped us in parsing the response from AWS Lambda into separate JSON objects, enabling us to process the data easily.

            moves = (JSONArray) parser.parse(response);
            ...
            JSONObject json = (JSONObject) moves.get(index_moves++);
    
  • MySQL Connector We use MySQL Connector to enable interaction and connection to our AWS database, since it provides the required driver.

      conn = DriverManager.getConnection(dbURL, "admin", "mypassword");
      ...
      ResultSet rs = stmt.executeQuery(query);