Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class DinosaurController {
private Entity score;
private Entity life;
private Entity bomb;
private Entity coin;
private CoinComponent coinComponent;

/**
* Summary :
Expand Down Expand Up @@ -72,12 +74,12 @@ public void initInput() {

public void initGame() {
getGameWorld().addEntityFactory(new GameEntityFactory());
spawn("background", 0, 0);
spawn("background", 0, 0);

player = spawn("player", getAppCenter().getX() - 45, getAppHeight() - 200);

FXGL.play(GameConstants.BACKGROUND_SOUND);

/*
* At each second that passes, we have 2 out of 3 chances of spawning a green
* dinosaur
Expand All @@ -87,16 +89,35 @@ public void initGame() {
if (random(0, 2) < 2)
spawn("greenDino", random(0, getAppWidth() - 80), -50);
}, seconds(0.75));



/*
*
*
*
*
*/
Comment on lines +93 to +98

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This large, empty comment block appears to be a leftover from development and adds unnecessary clutter to the code. It should be removed for better readability.

Comment on lines +93 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty Comment Block

Empty comment block with no content violates organization guideline against commented code in codebases. This creates visual noise and reduces code readability without providing any documentation value.

Standards
  • Clean Code
  • Org-Guideline-Avoid commented code in actual codebases

Comment on lines +93 to +98
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion | 🟠 Major

Remove the empty comment block.

The comment block contains no useful information and serves no purpose.

Apply this diff to remove the empty comment block:

-        /*
-         *
-         *
-         *
-         *
-         */
-
         run(() -> {
πŸ€– Prompt for AI Agents
In
src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java
around lines 93 to 98, there's an empty multi-line comment block that provides
no information; remove the entire /* ... */ block so the file contains no
redundant blank comments, keeping surrounding code and formatting intact.


run(() -> {
if (random(0, 100) < 20) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic Number Usage

Hardcoded probability value 20 violates organization guideline against variable hardcoding. Magic numbers reduce maintainability and make game balance adjustments difficult without code changes.

Standards
  • Clean Code
  • Org-Guideline-Hardcoding of variables

double x = random(0, getAppWidth() - 80);
System.out.println("Spawning coin at x=" + x + ", y = 0");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This System.out.println statement seems to be for debugging. It's best practice to remove these from production code to avoid cluttering the console. If logging is needed, consider using FXGL's built-in logger, for example: getGameLogger().info(...).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Code Removal

Debug print statement should be removed from production code. Console output in game loop can impact performance and creates unnecessary log noise in production environments.

Standards
  • Clean Code
  • Production Code Standards

spawn("coin", x, 0);
}
}, seconds(1.0));


score = spawn("Score", getAppCenter().getX() - 270, getAppCenter().getY() - 320);
life = spawn("Life", getAppCenter().getX() - 260, getAppCenter().getY() - 250);
bomb = spawn("Bomb", getAppCenter().getX() - 260, getAppCenter().getY() - 180);

coin = spawn("Coins", getAppCenter().getX() - 260, getAppCenter().getY() - 120);
System.out.println("Coins at : " + coin.getPosition());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This System.out.println statement appears to be for debugging purposes. It should be removed to keep the application's console output clean.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Code Removal

Debug print statement should be removed from production code. Console output during initialization creates unnecessary log entries and violates clean code practices.

Standards
  • Clean Code
  • Production Code Standards

coinComponent = coin.getComponent(CoinComponent.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The getComponent() method can return null if the entity spawned as "Coins" does not have a CoinComponent. This would lead to a NullPointerException in the collision handler when coinComponent.incrementCoin() is called. To make the code more robust, you should add a null check and fail fast with a clear error message if the component is missing.

Suggested change
coinComponent = coin.getComponent(CoinComponent.class);
coinComponent = coin.getComponent(CoinComponent.class);
if (coinComponent == null) {
throw new IllegalStateException("The 'Coins' UI entity must have a CoinComponent. Please check the GameEntityFactory.");
}


Comment on lines +112 to +115
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | πŸ”΄ Critical

🧩 Analysis chain

Verify entity type naming consistency.

The code spawns an entity named "Coins" (plural, capitalized) at Line 112, but the collision handler references EntityType.COIN (singular, uppercase) at Line 148, and the spawning logic uses "coin" (singular, lowercase) at Line 104. Ensure that:

  1. GameEntityFactory defines both "coin" (for collectible coins) and "Coins" (for the UI counter)
  2. EntityType enum includes a COIN value
  3. The naming convention is intentional and documented

Also, consider using a logger instead of System.out.println at Line 113.

Run the following script to verify the entity types and factory definitions:


🏁 Script executed:

#!/bin/bash
# Description: Check for coin-related entity definitions in GameEntityFactory and EntityType enum

# Search for entity type definitions
echo "=== Searching for EntityType.COIN enum definition ==="
ast-grep --pattern 'enum EntityType {
  $$$
}'

echo -e "\n=== Searching for coin entity factory methods ==="
rg -nP --type=java -C3 'spawn\w*\("(?i)coins?"\)|@Spawns\("(?i)coins?"\)'

echo -e "\n=== Searching for EntityType references ==="
rg -nP --type=java 'EntityType\.COIN'

Length of output: 313


🏁 Script executed:

#!/bin/bash
# Locate EntityType.java
echo "=== Locating EntityType.java ==="
fd EntityType.java -t f

# Inspect EntityType enum for COIN
echo -e "\n=== Inspecting EntityType enum for COIN ==="
sed -n '1,200p' "$(fd EntityType.java -t f)" | grep -n 'enum EntityType' -A50 || echo "EntityType enum not found or no COIN entry"

# Locate GameEntityFactory.java
echo -e "\n=== Locating GameEntityFactory.java ==="
fd GameEntityFactory.java -t f

# Inspect GameEntityFactory for coin spawn definitions
echo -e "\n=== Searching in GameEntityFactory for 'coin' ==="
grep -RIn 'coin' "$(fd GameEntityFactory.java -t f)"

Length of output: 411


Add missing COIN entity type and spawn registrations

  • EntityType.java: add COIN to the enum.
  • GameEntityFactory.java: register both "coin" (collectible) and "Coins" (UI counter) spawn keys.
  • DinosaurController.java line 113: replace System.out.println with a logger.
πŸ€– Prompt for AI Agents
In
src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java
around lines 112-115, replace the System.out.println call with the class logger
(e.g., logger.info/ debug) to log the coin position; ensure you reference the
existing logger instance on the controller. In
src/main/java/com/dinosaur/dinosaurexploder/model/EntityType.java add COIN to
the enum values. In
src/main/java/com/dinosaur/dinosaurexploder/factory/GameEntityFactory.java
register two spawn keys: the collectible key "coin" mapped to the collectible
Coin entity/component and the UI counter key "Coins" mapped to the UI coin
counter entity/component (use the existing factory registration pattern and
correct class constructors or suppliers), ensuring keys match the strings used
in spawn calls.


bomb.addComponent(new BombComponent());
}


/**
* Summary :
* Detect the collision between the game elements.
Expand Down Expand Up @@ -124,6 +145,12 @@ public void initPhysics() {
System.out.println("You touched a dino !");
damagePlayer();
});
onCollisionBegin(EntityType.PLAYER, EntityType.COIN, (player, coin) -> {
FXGL.play(GameConstants.COIN_GAIN);
coin.removeFromWorld();
System.out.println("You touched a coin!");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This System.out.println statement is likely a debug message. It should be removed before merging to avoid polluting the console output.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug Code Removal

Debug print statement should be removed from production code. Console output in collision detection can impact game performance and creates unnecessary log noise.

Standards
  • Clean Code
  • Production Code Standards

coinComponent.incrementCoin();
Comment on lines +148 to +152
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Avoid shadowing the class field coin inside the collision lambda and guard the UI update with a null-check to prevent a NullPointerException if coinComponent isn't initialized. [possible bug]

Suggested change
onCollisionBegin(EntityType.PLAYER, EntityType.COIN, (player, coin) -> {
FXGL.play(GameConstants.COIN_GAIN);
coin.removeFromWorld();
System.out.println("You touched a coin!");
coinComponent.incrementCoin();
onCollisionBegin(EntityType.PLAYER, EntityType.COIN, (player, coinPickup) -> {
FXGL.play(GameConstants.COIN_GAIN);
coinPickup.removeFromWorld();
System.out.println("You touched a coin!");
if (coinComponent != null) {
coinComponent.incrementCoin();
} else {
System.out.println("Warning: coinComponent is null; coin counter not updated.");
}
Why Change? ⭐

The improved code makes two small, local changes:

  1. Renames the lambda parameter from 'coin' to 'coinPickup' so it no longer shadows the class field 'coin'. This avoids confusion and potential accidental use of the field instead of the method parameter. Java allows this rename in a lambda; syntax remains valid.
  2. Adds a null-check before calling coinComponent.incrementCoin(), preventing a possible NullPointerException if coinComponent hasn't been initialized for any reason. It also logs a warning when coinComponent is null.

These changes compile in the existing context (no new imports or API usage). The code references (onCollisionBegin, EntityType, FXGL, GameConstants, coinComponent) already exist in the class/diff. The guard is conservative and safe: if coinComponent is always initialized in initGame (as shown in the PR), this is a no-op; if not, it prevents a runtime crash. There is no change in control flow or behavior except the added safety and logging, so it won't break production.

Assumptions:

  • initGame sets coin and coinComponent as shown in the PR, but if a race or ordering issue exists, the null-check handles it safely.
  • CoinComponent class and its incrementCoin() method exist as used elsewhere in the code.

Given the above, the suggestion is syntactically correct, executable, and does not introduce bugs.

});
Comment on lines +148 to +153
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | πŸ”΄ Critical

🧩 Analysis chain

Missing constant GameConstants.COIN_GAIN causes compilation failure.

Line 149 references GameConstants.COIN_GAIN, but this constant is not defined in the provided GameConstants.java snippet (lines 10-42 show other sound constants like SHOOT_SOUND, ENEMY_EXPLODE_SOUND, etc., but no COIN_GAIN). This will cause a compilation error.

Additionally, consider using a logger instead of System.out.println at Line 151.

Add the missing constant to GameConstants.java:

public static final String COIN_GAIN = "coinGain.wav";

Ensure the corresponding sound file exists in the assets directory.

Run the following script to verify:


🏁 Script executed:

#!/bin/bash
# Description: Check if COIN_GAIN constant exists and verify sound file

echo "=== Checking for COIN_GAIN constant in GameConstants ==="
rg -nP --type=java 'COIN_GAIN\s*='

echo -e "\n=== Checking for coin-related sound files ==="
fd -e wav -i coin

Length of output: 103


Add missing constant, asset, and replace println with logger

  • Define in GameConstants.java:
    public static final String COIN_GAIN = "coinGain.wav";
    and add coinGain.wav to your assets/sounds folder.
  • Replace System.out.println("You touched a coin!"); with a logger call (e.g., logger.info("You touched a coin!");).
πŸ€– Prompt for AI Agents
In
src/main/java/com/dinosaur/dinosaurexploder/controller/DinosaurController.java
around lines 148–153, replace the hardcoded sound name and System.out.println:
add a constant public static final String COIN_GAIN = "coinGain.wav" to
GameConstants.java and place coinGain.wav into assets/sounds, update the
FXGL.play call to use GameConstants.COIN_GAIN, and replace
System.out.println("You touched a coin!"); with a logger.info(...) call (ensure
a logger field/import is present in the controller, e.g., private static final
Logger logger = LoggerFactory.getLogger(DinosaurController.class)).

}

/**
Expand Down