-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Added Clicker game functionality
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/widgets/minigames/games/ClickerGame.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}. | ||
| * | ||
| * <p>Extends {@link ViewElement}</p> | ||
| * | ||
| * <p>Implements {@link GameGimmick}</p> | ||
| * */ | ||
| public final class ClickerGame | ||
| extends ViewElement<VBox, MiniGamesActions> | ||
| 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. | ||
| } | ||
| } |