Skip to content
Go back

SMOL

Suggest changes

Situation

During my Object Oriented Programming (OOP) course at university, I collaborated with three classmates to develop a 2D arcade game called ‘SMOL’ using Java and JavaFX. The goal was to create a top-down game where players defend vegetable fields from invading moles by smashing them with a hammer. The game increases in difficulty as the player’s score rises, decreasing the time between mole appearances and altering the probability of different mole types generating. This project required us to apply advanced programming concepts and design patterns within a tight timeline.

Tasks

My primary responsibilities in the project were twofold:

The challenge was to implement these features in alignment with the Model-View-Controller (MVC) architectural pattern, ensuring seamless interaction between the Model, View, and Controller components.

Action

Window Management

package it.unibo.smol.view.api;

import java.io.IOException;
import javafx.stage.Stage;

/**
* Interface where the implementation decides the behavior of the window.
*/

public interface WindowState {
    /**
    * Method that initialize the stage.
    * 
    * @param stage The stage where our game is running.
    * @throws IOException Exception if the stage can't be rendered.
    */
    void render(Stage stage) throws IOException;

}src/main/java/it/unibo/smol/view/api/WindowState.java
package it.unibo.smol.view.impl;

import java.io.IOException;
import java.util.logging.Level;
...

/**
* Implementation of the menu state, it renders the menu.
*/
public final class MenuState implements WindowState {
    private static Logger logger = Logger.getLogger("menuLogger");
    private static final int MENU_ANIM_DURATION = 500;
    private final GameEngine gameEngine = new GameEngineImpl();
    private String currentSkins;

    /**
    * constructor that generate a menu state with a default skin value.
    */
    public MenuState() {
        this.currentSkins = Constant.KEY_PIXEL_SKINS;
    }

    /**
    * constructor that generate a menu state with a decided skin value.
    * @param skins decided skin
    */
    public MenuState(final String skins) {
        this.currentSkins = skins;
    }
    /**
    * {@inheritDoc}
    */
    @Override
    public void render(final Stage primaryStage) throws IOException {
        try {
            this.start(primaryStage);
        } catch (IOException e) {
            logger.log(Level.SEVERE, "MenuStateError::", e);
        }
    }

        ... 

        primaryStage.show();
    }
    ... src/main/java/it/unibo/smol/view/impl/MenuState.java
package it.unibo.smol.view.impl;

...
import javafx.stage.WindowEvent;

/**
 * Implementation of the main state, it renders the game.
 */
public class GameViewState implements WindowState {

    /**
     * constructor made to get the gamseState.
     * @param gameState
     * @param keyInputs
     * @param mouseInputs
     */
    public GameViewState(final Optional<GameState> gameState,
        final Optional<KeyInputs> keyInputs, final Optional<MouseInputs> mouseInputs) {
        ...
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void render(final Stage stage) {
        ...
    }

    private void start(final Stage stage) throws IOException {
        final var root = new Pane();
        final var scene = new Scene(root, GameMap.WIDTH * GameMap.SCREEN_PROP_X - 1,
                GameMap.HEIGHT * GameMap.SCREEN_PROP_Y - 1, Color.BLACK);
        ...
        stage.show();
    }
    ...
}src/main/java/it/unibo/smol/view/impl/GameViewState.java

MVC Pattern

Game World Management

Collaboration and Communication

Results

Our team brought the game from concept to completion, delivering a smooth running JavaFX title that satisfied every project requirement while exemplifying sound object oriented design. By architecting the interface around the State pattern and delegating entity logic to a dedicated World class, we achieved a highly modular codebase that future developers can extend or refactor with minimal ripple effects. Along the way, I deepened my grasp of patterns such as State and Iterator, sharpened my Java and GUI programming skills, and saw firsthand how adhering to MVC principles promotes scalability and maintainability. Equally important, the project strengthened my teamwork and communication abilities as we wove our individual contributions into one cohesive, engaging product.

final result pixeled final result vectorial

More


Suggest changes
Share this post on:

Previous Post
SCALcetto
Next Post
Social4Musicians