Skip to content

Commit

Permalink
Feat: Clicker game rework
Browse files Browse the repository at this point in the history
Reworked the clicker game. Previously, the game was designed around clicking a static button and buying an upgrade for it. Now, the game works more like an aim trainer, where the button teleports after every click.
  • Loading branch information
tommyah committed May 24, 2026
1 parent 8888d44 commit 544cae7
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,27 @@ private void refreshMetrics() {
int seconds = secondsRemaining % 60;
String formattedTime = String.format("%02d:%02d:%02d", hours, minutes, seconds);

if (currentScore > 150) {
if (currentScore >= 150) {
currentRank = 'S';
rankEffectString = "Extremely good fortune awaits " + chosenStock.getSymbol();
fortuneToSet = 0.10;

} else if (currentScore > 120) {
} else if (currentScore >= 120) {
currentRank = 'A';
rankEffectString = "Really good fortune awaits " + chosenStock.getSymbol();
fortuneToSet = 0.5;

} else if (currentScore > 80) {
} else if (currentScore >= 80) {
currentRank = 'B';
rankEffectString = "Good fortune awaits " + chosenStock.getSymbol();
fortuneToSet = 0.2;

} else if (currentScore > 50) {
} else if (currentScore >= 50) {
currentRank = 'C';
rankEffectString = "Bad fortune awaits " + chosenStock.getSymbol();
fortuneToSet = -0.2;

} else if (currentScore > 20) {
} else if (currentScore >= 20) {
currentRank = 'D';
rankEffectString = "Really bad fortune awaits " + chosenStock.getSymbol();
fortuneToSet = -0.5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,18 @@ public void showHelpSection() {
VBox textContainer = new VBox();
textContainer.getStyleClass().add("minigames-help-text-vbox");

textContainer.getChildren().add(createTextParagraph("MINIGAMES",
textContainer.getChildren().add(createTextParagraph("Minigames",
"Welcome to the minigames section! Here you can boost a selected stock (choose in dashboard page)"
+ " by playing minigames! A minigame takes one minute, and you are able to exit before the time runs out."
+ " by playing minigames! A minigame takes 20 seconds, and you are able to exit before the time runs out."
+ " This will not have any negative effects. "
+ " When you complete a minigame, you get a rank based on your score. Higher scores yield a higher rank."
+ " The higher rank you are at the end of the round, the more fortune the selected stock will get."
+ " Every stock can only be boosted one time per week by playing minigames, so play minigames for all your investments!"));
+ " Every stock can only be boosted one time per week by playing minigames, so play minigames for all your investments!"
+ " (Multiple minigames for same stock overrides previous fortune.)"));

textContainer.getChildren().add(createTextParagraph("What are minigames?",
"A minigame is a short interactive experience where you are able to gain points by performing"
+ " task(s) that are differ from minigame to minigame. Each minigame session takes exactly one minute to complete"
+ " task(s) that are differ from minigame to minigame. Each minigame session takes 20 seconds to complete"
+ " from start to finish, and you will gain a report based on your performance at the end of the round."
+ " You can also choose to exit before a round ends to go back, but note that quitting after the round ends"
+ " will still cause the effect."));
Expand All @@ -146,11 +147,12 @@ public void showHelpSection() {
"In the minigame page, you can see your selected stock. This stock will then get a"
+ " positive or negative flat percent amount added to their next weekly price change, based on your rank."
+ " This is called the stocks fortune."
+ " Each stock can only be manipulated once per week by playing minigames, so be sure to"
+ " play minigames for all your investments!"));
+ " Each stock can only have a single fortune active per week, so be sure to"
+ " play minigames for all your investments! Playing multiple minigames for the same"
+ " stock will override the stocks' fortune."));

textContainer.getChildren().add(createTextParagraph("Minigame 1: Clicker Minigame",
"Click the primary action tile to increase points. Balance your point allocation strategy between immediate click returns and structural upgrades."));
"Click the button to earns points. The button changes location after every click!"));

textContainer.getChildren().add(createTextParagraph("Minigame 2: Find The Stock",
"Scan the choice matrix panel grid and find the symbol matching the target description. Incorrect selections will deduct points."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,71 @@
import java.util.function.IntConsumer;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.layout.Pane;

/**
* Clicker minigame, found in the
* {@link edu.ntnu.idi.idatt2003.g40.mappe.view.widgets.minigames.MiniGamesView}.
* Clicker minigame where the goal is to hit the targets as much
* as possible.
*
* <p>Extends {@link ViewElement}</p>
*
* <p>Implements {@link GameGimmick}</p>
* */
public final class ClickerGame
extends ViewElement<VBox, MiniGamesActions>
extends ViewElement<Pane, MiniGamesActions>
implements GameGimmick {

/**
* The score to increase when clicking the main button.
* How many points to get after clicking the button.
* */
private int clickValue;

/**
* Local reference to current score.
*/
private int score;

/**
* The current cost of upgrading the amount gained per click.
* */
private int upgradeCost;

/**
* The click button object.
* Button pressed to give points.
* */
private Button clickBtn;

/**
* The upgrade button object.
* */
private Button upgradeBtn;

/**
* Constructor.
* */
public ClickerGame() {
super(new VBox(), MiniGamesActions.class);
super(new Pane(), MiniGamesActions.class);
}

@Override
protected void initLayout() {
clickValue = 1;
upgradeCost = 10;
clickValue = 6;
clickBtn = new Button("+" + clickValue);
upgradeBtn = new Button("+" + clickValue + " per click\n-"
+ upgradeCost + " points");
getRootPane().getChildren().addAll(clickBtn, upgradeBtn);
clickBtn.setFocusTraversable(false);

// Initial position.
clickBtn.setLayoutX(260);
clickBtn.setLayoutY(160);

getRootPane().getChildren().add(clickBtn);

// Responsive listener for width. Pushes the button to the edge of the
// screen if it is outside of it.
getRootPane().widthProperty().addListener((obs, oldVal, newVal) -> {
double maxAllowedX = newVal.doubleValue() - clickBtn.getWidth();
if (clickBtn.getLayoutX() > maxAllowedX) {
clickBtn.setLayoutX(Math.max(10, maxAllowedX));
}
});

// Same responsive listener for height.
getRootPane().heightProperty().addListener((obs, oldVal, newVal) -> {
double maxAllowedY = newVal.doubleValue() - clickBtn.getHeight();
if (clickBtn.getLayoutY() > maxAllowedY) {
clickBtn.setLayoutY(Math.max(10, maxAllowedY));
}
});
}

@Override
protected void initStyling() {
getRootPane().getStyleClass().add("clicker-minigame-root");
clickBtn.getStyleClass().add("clicker-minigame-clickBtn");
upgradeBtn.getStyleClass().add("clicker-minigame-upgradeBtn");
}

@Override
Expand All @@ -76,23 +80,29 @@ public Node getCanvasNode() {

@Override
public void initialize(final IntConsumer scoreModifier) {
score = 0;
clickBtn.setOnAction(e -> {
scoreModifier.accept(clickValue);
score += clickValue;
teleportTarget();
});
}

upgradeBtn.setOnAction(e -> {
scoreModifier.accept(-upgradeCost);
if (upgradeCost <= score) {
score -= upgradeCost;
clickValue += 1;
upgradeCost *= 2;
clickBtn.setText("+" + clickValue);
upgradeBtn.setText("+1 per click\n-"
+ upgradeCost + " points");
}
});
/**
* Teleports the click target to a new random coordinate
* set inside the current view boundaries.
*
* <p>Calculates maximum allowed x and y position
* based on the view/button width/height.</p>
*/
private void teleportTarget() {

double maxX = getRootPane().getWidth() - clickBtn.getWidth();
double maxY = getRootPane().getHeight() - clickBtn.getHeight();

double randomX = Math.random() * maxX;
double randomY = Math.random() * maxY;

clickBtn.setLayoutX(Math.max(10, randomX));
clickBtn.setLayoutY(Math.max(10, randomY));
}

@Override
Expand Down
10 changes: 3 additions & 7 deletions src/main/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@
-fx-text-fill: #000000;
-fx-text-alignment: center;
-fx-pref-height: 250px;
-fx-min-height: 200px;
-fx-min-height: 100px;
-fx-max-width: 350px;
}

Expand Down Expand Up @@ -991,12 +991,8 @@
}

.clicker-minigame-clickBtn {
-fx-pref-width: 100;
-fx-pref-height: 100;
}

.clicker-minigame-upgradeBtn {
-fx-text-alignment: center;
-fx-pref-width: 80;
-fx-pref-height: 80;
}
/*--------------- TIMED INPUT GAME -------------*/
.time-inputs-minigame-root {
Expand Down

0 comments on commit 544cae7

Please sign in to comment.