Добрый день, нужна ваша помощь, пролистал все темы по данному вопросу не нашел своей ошибки.
gameEngine.js
import { init } from "./functions.js";
import { handleKeyPress, handleStateChange } from "./handlers.js";
export const startMiningGame = (term, state) => {
init(term) ;
term.on('key', handleKeyPress(term, state));
setInterval(() => handleStateChange(term, config), 1000);
}
handlers.js
import { updateGold } from "./functions";
export const handleKeyPress = (term, state) => {
return (name, matches, data) => {
if (String.fromCharCode(data.code) === "g" || String.fromCharCode(data.code) === "G") {
state.gold = state.gold + 1;
handleKeyPress(term, state)
}
for (let i = 0; i < state.producers.length; i++) {
if (String.fromCharCode(data.code)===`${state.producers[i].id}`) {
state.gold = state.gold - state.producers[i].cost
state.producers[i].cost = state.producers[i].cost*state.producers[i].growthRate
state.producers[i].count = state.producers[i].count + 1
state.productionRate += state.producers[i].baseProduction;
}
}
}
}
export const handleStateChange = (term, state) => ()=> {
return updateGold(term, state);
};