|
|
@@ -0,0 +1,21 @@
|
|
|
+const VM = require('./lib/vm')
|
|
|
+const fs = require('fs')
|
|
|
+const data = fs.readFileSync('./games/ZORK1.DAT')
|
|
|
+const saveFile = './zork1.sav'
|
|
|
+
|
|
|
+const main = async () => {
|
|
|
+ let state
|
|
|
+ if (fs.existsSync(saveFile)) {
|
|
|
+ state = JSON.parse(fs.readFileSync(saveFile, 'utf8'))
|
|
|
+ } else {
|
|
|
+ state = await VM.play(data)
|
|
|
+ }
|
|
|
+ while (state) {
|
|
|
+ fs.writeFileSync(saveFile, JSON.stringify(state), 'utf8')
|
|
|
+ if (typeof state.output === 'string') process.stdout.write(state.output)
|
|
|
+ const text = (await new Promise(resolve => process.stdin.once('data', resolve))).toString()
|
|
|
+ state = await VM.play(data, state.save, text.toString().trim())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+main().catch(console.error)
|