From 4da73008276b1bc07d97b6d9e6be13ce19a65989 Mon Sep 17 00:00:00 2001 From: = Date: Sat, 23 May 2026 19:03:19 +0200 Subject: [PATCH] Feat: Added Clicker game functionality --- .../widgets/minigames/games/ClickerGame.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/ClickerGame.java diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/ClickerGame.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/ClickerGame.java new file mode 100644 index 0000000..f2d9f06 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/ClickerGame.java @@ -0,0 +1,92 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.games; + +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement; +import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.GameGimmick; +import edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesActions; +import java.util.function.IntConsumer; +import javafx.scene.Node; +import javafx.scene.control.Button; +import javafx.scene.layout.VBox; + +/** + * Clicker minigame, found in the + * {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesView}. + * + *

Extends {@link ViewElement}

+ * + *

Implements {@link GameGimmick}

+ * */ +public final class ClickerGame + extends ViewElement + implements GameGimmick { + + /** + * The score to increase when clicking the main button. + * */ + private int clickValue; + + /** + * The current cost of upgrading the amount gained per click. + * */ + private int upgradeCost; + + /** + * The click button object. + * */ + private Button clickBtn; + + /** + * The upgrade button object. + * */ + private Button upgradeBtn; + + /** + * Constructor. + * */ + public ClickerGame() { + super(new VBox(), MiniGamesActions.class); + } + + @Override + protected void initLayout() { + clickValue = 1; + upgradeCost = 10; + clickBtn = new Button("+" + clickValue); + upgradeBtn = new Button("+" + clickValue + " per click\n-" + + upgradeCost + " points"); + getRootPane().getChildren().addAll(clickBtn, upgradeBtn); + } + + @Override + protected void initStyling() { + getRootPane().getStyleClass().add("clicker-minigame-root"); + clickBtn.getStyleClass().add("clicker-minigame-clickBtn"); + upgradeBtn.getStyleClass().add("clicker-minigame-upgradeBtn"); + } + + @Override + public Node getCanvasNode() { + return getRootPane(); + } + + @Override + public void initialize(final IntConsumer scoreModifier) { + + clickBtn.setOnAction(e -> scoreModifier.accept(clickValue)); + + upgradeBtn.setOnAction(e -> { + // TODO: Change validation to only upgrade if enough score. + scoreModifier.accept(-upgradeCost); + clickValue += 1; + upgradeCost *= 2; + clickBtn.setText("+" + clickValue); + upgradeBtn.setText("+" + clickValue + " per click\n-" + + upgradeCost + " points"); + }); + } + + @Override + public void updateTick() { + // No need to auto update information for this game. + } +}