Skip to content

Boss defeat logic is duplicated causing score to be awarded twice when boss HP reaches zero #24

Description

@woydarko

Bug Description

When the boss HP reaches zero, the score increment and end screen logic runs twice due to duplicated code in the handleKeyPress function. The player receives +100 score twice (total +200) and showEndScreen is called twice in the same event.

Steps to Reproduce

  1. Start the game and reach Stage 3
  2. Defeat the boss by typing all its words until HP reaches 0
  3. Observe the final score — it will show 200 points more than expected

Expected Behavior

When boss HP reaches 0, score should increment by +100 exactly once and showEndScreen("Selamat! Kamu Menang!") should be called once.

Actual Behavior

The following block runs twice consecutively in handleKeyPress:

score += 100;
showPopup(pest.element, "+100", "score");
pest.element.remove();
activePests.splice(i, 1);
showEndScreen("Selamat! Kamu Menang!");

This is because the if (pest.hp <= 0) check appears twice back-to-back in the source code without an else branch separating them.

Root Cause

In script.js, inside the handleKeyPress function under the boss word completion block, the if (pest.hp <= 0) condition and its entire body is copy-pasted twice. The second block runs immediately after the first.

Environment

  • Chrome 122 / Firefox 124
  • All platforms

Wallet: 0x964739472C587d24934c37BEbB405CeE36D59B24

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions