import { advanceState } from "./game"; import { Action } from "./game/types"; import { createSessionState, SessionState } from "./state"; import { renderState, createAndBindHandler, prepareTerminal, Key } from "./ui"; export const run = async () => { let state: SessionState = createSessionState("xyz"); let actionQueue: Action[] = []; const updateAction = (key: Key) => { if (actionQueue.length > 1) { actionQueue = actionQueue.slice(1); } switch (key) { case Key.LEFT_ARROW: actionQueue.push(Action.MOVE_LEFT); break; case Key.RIGHT_ARROW: actionQueue.push(Action.MOVE_RIGHT); break; default: break; } }; prepareTerminal(); createAndBindHandler(updateAction, process.exit); while (true) { let nextAction = actionQueue.pop(); state = await advanceState(state, nextAction); renderState(state); } }; run().then(console.log).catch(console.error);