Add XP penalties for repeated misses and timeout

This commit is contained in:
chris 2025-11-20 10:52:53 -05:00
parent 61e332a309
commit 023727d7a4

15
app.js
View File

@ -819,12 +819,18 @@
grid.classList.add('has-stars');
}
function applyPenalty(amount) {
if (!amount) return;
state.currentLevelXP = Math.max(0, state.currentLevelXP - amount);
}
function handleWrongAttempt(options = {}) {
const { timedOut = false } = options;
const feedback = document.getElementById('feedback-msg');
const card = document.querySelector('.card-container');
state.streak = 0;
game.attempts = timedOut ? 3 : game.attempts + 1;
const penalty = game.attempts >= 3 || timedOut ? 10 : (game.attempts === 2 ? 5 : 0);
if (card) {
card.classList.add('apply-shake');
setTimeout(() => card.classList.remove('apply-shake'), 500);
@ -834,13 +840,14 @@
game.currentInput = "";
document.getElementById('answer-display').innerText = "";
}
if (penalty > 0) applyPenalty(penalty);
if (game.attempts >= 3) {
revealAnswerAndAdvance(timedOut ? 2000 : 0, timedOut);
revealAnswerAndAdvance(timedOut ? 2000 : 0, timedOut, penalty);
return;
}
if (game.attempts === 2) {
feedback.style.color = '#ffb0b0';
feedback.innerText = "Count the stars...";
feedback.innerText = `Count the stars... (-${penalty} XP)`;
drawHintGrid(game.currentFact.n1, game.currentFact.n2);
} else {
feedback.style.color = '#ffb0b0';
@ -849,7 +856,7 @@
saveData(); updateUI();
}
function revealAnswerAndAdvance(delayMs = 0, timedOut = false) {
function revealAnswerAndAdvance(delayMs = 0, timedOut = false, penalty = 0) {
const feedback = document.getElementById('feedback-msg');
const card = document.querySelector('.card-container');
const factId = `${Math.min(game.currentFact.n1, game.currentFact.n2)}x${Math.max(game.currentFact.n1, game.currentFact.n2)}`;
@ -863,7 +870,7 @@
setTimeout(() => card.classList.remove('apply-shake'), 500);
}
feedback.style.color = '#ffb0b0';
feedback.innerText = `Answer is ${game.currentFact.ans}. Press CAST to continue.`;
feedback.innerText = `Answer is ${game.currentFact.ans}.${penalty ? ` (-${penalty} XP)` : ''} Press CAST to continue.`;
addToTroubleList(game.currentFact.n1, game.currentFact.n2);
game.currentInput = game.currentFact.ans.toString();
const answerDisplay = document.getElementById('answer-display');