Skip to content

Instantly share code, notes, and snippets.

@stenno
Last active February 10, 2019 16:17
Show Gist options
  • Save stenno/05b136d679de8c27b2ea1195be21353f to your computer and use it in GitHub Desktop.
Save stenno/05b136d679de8c27b2ea1195be21353f to your computer and use it in GitHub Desktop.
Nethack API Frontend WIP
const NethackAPI = require("./nethackapi");
const nethackAPI = new NethackAPI();
// lazy top-level await
(async () => {
// connect to HDF
await nethackAPI.loginSSH("stenno", "not my password", "nethack@eu.hardfought.org");
if (!nethackAPI.connected) {
throw "Couldn't connect :(";
}
// get version from extcommand -> prints to text window
await nethackAPI.doInput("#version\n");
const versionText = nethackAPI.getTextWindow();
console.log(versionText.join("\n"));
await nethackAPI.doInput(" "); // close version window
// phew, enough playing, let's Save and exit
await nethackAPI.doInput("S");
// print last message
// should print string 'Really save? [yn] (n) °'
console.log("messages", nethackAPI.messages.slice(-1));
// yes, we want to Save
await nethackAPI.doInput("y");
// close connection
nethackAPI.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment