Подскажите пожалуйста, что не так?
Застрял на последнем этапе
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 + ' ');
}
export const checkInitCompleted = (term, state) => {
state.isInitCompleted = true;
state.isProducerListUpdated = false;
term.moveTo(1, 1);
term.eraseLine();
term('You can purchase producers by clicking the number button (1, 2, 3, ...)');
term.moveTo(1, 2);
term('GOLD:');
term.moveTo(1, 3);
term('PRODUCTION RATE:');
}
export const updateProducerList = (term, state) => {
let j = 0;
let isOneZeroCountPrinted = false;
for (let i = 0; i < state.producers.length; i++) {
if (state.producers.count > 0 || (!isOneZeroCountPrinted && state.producers.count === 0)) {
term.moveTo(1, 5 + j);
term(${state.producers[i].title}: ${state.producers[i].count} | Production per second: ${state.producers[i].baseProduction.toFixed(1)} | Cost: ${state.producers[i].cost.toFixed(1)}
);
term.eraseLineAfter();
if (state.producers[i].count === 0){
isOneZeroCountPrinted = true;
}
j++;
}
}
state.isProducerListUpdated = true;
}
export const formatNumber = (n) => {
if ( n < 1000 ) {
return n.toFixed(1);
}
if ( (n >= 1000) && (n < 1000000) ) {
return (n/1000).toFixed(2) + 'K';
}
if ( (n >= 1000000) && (n < 1000000000)) {
return (n/1000000).toFixed(2) + 'M';
}
if ( (n >= 1000000000) && (n < 1000000000000)) {
return (n/1000000000).toFixed(2) + 'B';
}
if (n >= 1000000000000) {
return (n/1000000000000).toFixed(2) + 'T';
}
}
,,,
handlers.js
import { updateGold, checkInitCompleted, updateProducerList, } from './functions.js';
export const handleKeyPress = (term, state) => {
return function gameTable(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[i].id)) {
state.gold -= state.producers[i].cost;
state.producers[i].cost *= state.producers[i].growthRate;
state.producers[i].count++;
const productionRate = (state.producers[i].baseProduction / 1000) * state.tickSpeed;
state.productionRate += productionRate;
term.green(state.productionRate);
}
}
}
let minCost = 0;
for (const producer of state.producers) {
if (minCost === 0 || minCost > producer.cost) {
minCost = producer.cost;
}
}
if (state.gold >= minCost && !state.isInitCompleted) {
checkInitCompleted(term, state);
}
if (!state.isProducerListUpdated) {
updateProducerList(term, state);
}
}
}
export const handleStateChange = (term, state) => () => {
updateGold(term, state);
}