@Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        gameActive = true;

        // Initialize the start time.
        startTime = System.currentTimeMillis();

        // Create our field.
        field = new FieldModel();
        field.addEventListener(new FieldEventListener() {
            @Override
            public void handle(FieldEventType type) {
                switch (type) {
                    case TRY:
                        tries++;
                        break;
                    case CLEAR:
                        points++;
                        break;
                    case FAIL:
                        break;
                    case ALL_BRICKS_CLEARED:
                        gameActive = false;
                        gameOverText.setVisible(true);

                        // Workaround to prevent application hang on shutdown.
                        if (updateTimer != null)
                            updateTimer.cancel();
                        updateTimer = null;
                        break;
                }

                // Update text objects.
                pointsText.setText("Points: " + points);
                triesText.setText("Tries: " + tries);
            }
        });

        // Add the ImageView for each brick.
        int count = field.getBrickCount();
        for (int i = 0; i < count; i++) {
            final BrickModel brick = field.getBrick(i);
            final ImageView imageView = brick.getImageView();

            // Set a mouse click listener to flip bricks via field,
            // which will run all the necessary checks.
            imageView.setOnMouseClicked(new EventHandler<javafx.scene.input.MouseEvent>() {
                @Override
                public void handle(javafx.scene.input.MouseEvent mouseEvent) {
                    if (field.isTryInProgress())
                        return;
                    field.flipBrick(brick);
                }
            });

            // Fancy formulas to distribute the bricks in rows of 5.
            int column = i % 5;
            int row = (int) Math.floor(i / 5) + 1;
            window.add(imageView, column, row);
        }

        // We need to explicitly cancel the game on window close or the application will stay open in
        // the background, stuck because of the shitty way Java timers are designed.
        // SERIOUSLY JAVA?
        // F**king language...
        window.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                cancelGame();
            }
        });

        // Initialize the time display by calling the update method.
        updateTime();
    }