Repository navigation
Fixes for NPCs and Testing
Tickets: #462 (NPC polish and bug fixes), #490 (coverage tests)
In Sprint 4, I focused on polishing the NPC implementation and improving test coverage across several game systems. I fixed NPC dialogue and spawning bugs, corrected NPC positions, and added tests for dialogue, player touch input, and the tutorial UI.
I moved two NPCs to improve their placement in the game:
| NPC | Change | Reason |
|---|---|---|
| Wizard | Moved to the Nether ground floor near the lava | Previously spawned on top of an enemy |
| Philosopher | Moved to the first platform in Level 2 | Previous position was too close to a portal |
I updated the relevant map markers in level1-greek.json and level2.json.
I fixed several issues in DialogueComponent:
| Problem | Fix |
|---|---|
| Greeting dialogue was skipped | Fixed the dialogue progression so the greeting displays correctly |
| Quest completion needed an extra key press | The completion result now appears and clears on the same press |
| Dialogue repeated indefinitely | Fixed the closing behaviour so pressing E can end the conversation |
These changes make conversations and quest progression more predictable.
I added a null check in LevelGameArea.spawnNpcs() before accessing the current level. This prevents the method from trying to use a level that has not been loaded.
The shop-key fix had already been merged into main, so I removed my duplicate implementation and updated ShopkeeperComponentTest to test the existing behaviour.
During manual testing, I verified that H opens the shop and F performs the special attack.
The dialogue component handles player interactions with NPCs, progresses through dialogue lines, processes quest interactions and closes the conversation when finished.
The following diagram shows the intended interaction flow:
flowchart TD
A([Player presses E]) --> B{Dialogue remaining?}
B -->|Yes| C[Display next line]
C --> A
B -->|No| D{Quest interaction?}
D -->|Yes| E[Process quest interaction]
E --> F[Display quest result]
F --> G{Conversation finished?}
D -->|No| G
G -->|No| A
G -->|Yes| H([Close dialogue])
I added and extended unit tests to verify the NPC fixes and improve regression coverage across existing game systems.
| Test class | What it tests |
|---|---|
DialogueComponentTest |
Dialogue greetings, progression, quest completion and closing conversations |
ShopkeeperComponentTest |
Shop interaction behaviour |
SpinningTextureRenderComponentTest |
Spinning texture rendering |
LevelGameAreaSpawnNpcsTest |
NPC spawning when no level has been loaded |
ProvokedComponentTest |
NPC provocation behaviour |
NpcQuestRegistryTest |
NPC quest registry behaviour |
This PR added 21 test methods (29 test cases) across two new test files and the existing DialogueComponentTest. It changed test files only and did not modify game code.
| Test class | What it tests |
|---|---|
TouchPlayerInputComponentTest |
Movement in all four directions, stopping on key release, diagonal movement, opposite keys cancelling, unrelated keys being ignored, and attacking on touch |
TutorialTest |
Guide visibility, toggling, fade-in and fade-out, toggling during a fade, and disposal |
DialogueComponentTest |
Enemy, gold-spending and shield quests, error-state retries, unknown quest types, changing quest parameters, empty dialogue, and dialogue line tracking |
These tests cover normal behaviour and edge cases, helping catch regressions when the systems are changed in future.
The following checks passed for PR #464 and #499:
./gradlew compileJava./gradlew test./gradlew formatCheck
Both PRs passed their GitHub checks, received reviews and were merged into main.
The NPC fixes build on the Sprint 3 implementation rather than replacing it. The updated spawn positions use the existing level maps and NPC spawning system, while the dialogue fixes preserve the existing conversation and quest structure.
The additional tests cover player input, tutorial UI and dialogue behaviour, extending regression coverage across multiple systems that interact with the player.
-
Shop interaction: I initially implemented the shop-key fix because the shop interaction was conflicting with the special attack key. However, another change had already fixed the issue and was merged into
mainbefore my PR was merged. I removed my duplicate implementation and updatedShopkeeperComponentTestto test the existing behaviour instead, avoiding duplicate code. -
NPC spawning safety: While polishing the NPC implementation, I added a null check in
LevelGameArea.spawnNpcs()to handle cases where the current level had not been loaded. This also addressed a SonarCloud blocker. -
Test coverage: I expanded the scope of testing beyond the NPC fixes by adding tests for player touch input, tutorial behaviour, and additional dialogue edge cases. This helped improve regression coverage across existing game systems.