При проверке пишет такие ошибки.
checkInitCompleted должен вызываться из handleKeyPress, если у пользователя достаточно золота для первой покупки.
Аргументы handleKeyPress должны быть переданы в checkInitCompleted
checkInitCompleted должен вызываться из handleKeyPress только один раз за время существования игры.
functions.js
"""export const init = (term) => {
term('Welcome to the mining game!');
term.clear();
term.hideCursor();
term.grabInput();
};
export const updateGold = (term, state) => {
term.moveTo(25, 2);
term.eraseLineAfter();
term.bold.yellow(state.gold + ' ');
state.gold += state.productionRate;
};
export const checkInitCompleted = (term, state) => {
term.clear();
term.moveTo(25, 2);
term('You can purchase producers by clicking the number button (1, 2, 3, ...)');
term.moveTo(25, 2);
term.eraseLineAfter();
term(GOLD: ${state.gold}
);
term.moveTo(25, 2);
term.eraseLineAfter();
term(PRODUCTION RATE: ${state.productionRate}
);
};
"""
handlers.js
"""import { updateGold } from "./functions";
import { checkInitCompleted } from "./functions";
export const handleKeyPress = (term, state) => {
return function (name, matches, data) {
let key = String.fromCharCode(data.code);
if (key === 'g' || key === 'G') {
state.gold ++;
} else {
for (let i = 0; i < state.producers.length; i++) {
if (key === String(state.producers.id)) {
state.gold -= state.producers.cost;
state.producers.cost *= state.producers.growthRate;
state.producers.count++;
const productionRate = (state.producers.baseProduction / 1000) * state.tickSpeed;
state.productionRate += productionRate;
term.moveTo(25, 3);
}
}
}
if (!state.isInitCompleted) {
for (let i = 0; i < state.producers.length; i++) {
if (state.gold >= state.producers.cost) {
state.isInitCompleted = true;
checkInitCompleted(term, state);
}
}
}
//if (!state.isProducerListUpdated) {
//updateProducerList(term, state);
}
}
//}
export const handleStateChange = (term, state) => {
return () => { updateGold(term, state); };
};
"""
-
-