Skip to content

Commit

Permalink
Feat: Fixed clicker game
Browse files Browse the repository at this point in the history
Fixed bug where player could buy upgrade even if they did not have enough score, by adding an internal reference to score in the clicker game game.
  • Loading branch information
tommyah committed May 24, 2026
1 parent 3ab8e98 commit 5253d19
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public final class ClickerGame
* */
private int clickValue;

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

/**
* The current cost of upgrading the amount gained per click.
* */
Expand Down Expand Up @@ -71,17 +76,22 @@ public Node getCanvasNode() {

@Override
public void initialize(final IntConsumer scoreModifier) {

clickBtn.setOnAction(e -> scoreModifier.accept(clickValue));
score = 0;
clickBtn.setOnAction(e -> {
scoreModifier.accept(clickValue);
score += 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");
if (upgradeCost <= score) {
score -= upgradeCost;
clickValue += 1;
upgradeCost *= 2;
clickBtn.setText("+" + clickValue);
upgradeBtn.setText("+1 per click\n-"
+ upgradeCost + " points");
}
});
}

Expand Down

0 comments on commit 5253d19

Please sign in to comment.