По моему здесь ошибка в задании.
В задании написано:
Формат вывода должен быть таким:
Miner: 2 | Production per second: 0,1 | Cost: 12,8
Adventurer: 0 | Production per second: 1,0 | Cost: 100
Ошибку выдает следующую:
updateProducerList должна вывести информацию производителя в ожидаемом формате, используя единственную строку
functions.js
export const init = (term) => {
term.clear();
term ('Welcome to the mining game!');
term.hideCursor();
term.grabInput();
}
export const updateGold = (term, state) => {
term.moveTo(25, 2);
term.eraseLineAfter();
state.gold += state.productionRate;
term.bold.yellow(state.gold.toFixed(1) + ' ');
}
export const checkInitCompleted = (term, state) => {
term.moveTo(1, 1);
term.eraseLineAfter();
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:');
state.isInitCompleted = true;
state.isProducerListUpdated = false;
}
export const updateProducerList = (term, state) => {
let i = 0;
for (let j = 0; j< state.producers.length; j++) {
if (state.producers[j].count > 0) {
term.moveTo(1, 5 + i);
term(state.producers[i].title + ': ' + state.producers[i].count + ' | Production per second: ' + state.producers[i].baseProduction + ' | Cost: ' + state.producers[i].cost.toFixed(1));
i++;
}
}
if ((i === 0) || ((i > 0) && (i < state.producers.length))) {
term.moveTo(1, 5 + i);
term(state.producers[i].title + ': ' + state.producers[i].count + ' | Production per second: ' + state.producers[i].baseProduction + ' | Cost: ' + state.producers[i].cost.toFixed(1));
}
state.isProducerListUpdated = true;
}
handlers.js
import { checkInitCompleted, updateGold, updateProducerList } from "./functions.js";
export const handleKeyPress = (term, state) =>{
return (name, matches, data) => {
if (String.fromCharCode(data.code)==='g'||String.fromCharCode(data.code)==='G') {
state.gold++;
}
let minimalProducerCost = state.producers[0].cost;
for (const i in state.producers) {
if (minimalProducerCost>state.producers[i].cost) {
minimalProducerCost = state.producers[i].cost;
}
}
if ((state.gold>=minimalProducerCost)&&(state.isInitCompleted===false)) {
checkInitCompleted(term, state);
}
for (const i in state.producers) {
if ((String.fromCharCode(data.code)===String(state.producers[i].id)) && (state.gold>=state.producers[i].cost)) {
state.gold -= state.producers[i].cost;
state.producers[i].cost *= state.producers[i].growthRate;
state.producers[i].count++;
state.productionRate += state.producers[i].baseProduction;
state.isProducerListUpdated = false;
break;
}
}
if (state.isProducerListUpdated === false) {
updateProducerList(term, state);
}
}
}
export const handleStateChange = (term, state) => {
return () => {
updateGold(term, state);
}
}