summaryrefslogtreecommitdiff
path: root/src/run.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/run.ts')
-rw-r--r--src/run.ts37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/run.ts b/src/run.ts
new file mode 100644
index 0000000..c798f87
--- /dev/null
+++ b/src/run.ts
@@ -0,0 +1,37 @@
+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);