Coderslang_Master
---------------------functions.js-------------------
export const init = (term) => {
term('Welcome to the mining game!')
term
.clear()
.hideCursor()
.grabInput()
}
--------------------------------------
---------------------gameEngine.js-------------------
import {
init
} from "./functions.js"
import {
handleKeyPress
} from "./handlers.js"
export const startMiningGame = (term, state) => {
init(term)
const handler = handleKeyPress(term, state)
term.on('key', handler)
}
--------------------------------------
---------------------handlers.js-------------------
export const handleKeyPress = (term, state) => {
return (name, matches, data) => {
if (String.fromCharCode(data.code) == "g" ||
String.fromCharCode(data.code) == "G") {
return state.gold++
}
}
}
--------------------------------------
Наверное больше непонятно, как вызвать внутреннюю функцию с тремя параметрами(замыкание)