Commit to Deno project.
This commit is contained in:
11
.eslintrc
11
.eslintrc
@ -1,11 +0,0 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"ignorePatterns": ["node_modules", "dist", "*.validator.ts"]
|
||||
}
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,5 +2,4 @@
|
||||
.DS_Store
|
||||
|
||||
# Folders
|
||||
dist/*
|
||||
node_modules/*
|
||||
.vscode
|
||||
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"useTabs": true
|
||||
}
|
22
Scene.ts
Normal file
22
Scene.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { GameData, Item } from "./data/data.ts";
|
||||
|
||||
export default class Scene {
|
||||
#items: Item[];
|
||||
|
||||
constructor(gameData: GameData) {
|
||||
this.#items = gameData.items;
|
||||
}
|
||||
|
||||
take(target: string): Item | null {
|
||||
const idx = this.#items.findIndex(({ name }) => name === target);
|
||||
|
||||
if (idx >= 0) {
|
||||
const item = this.#items[idx];
|
||||
this.#items = this.#items.splice(idx, 1);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
19
console.ts
Normal file
19
console.ts
Normal file
@ -0,0 +1,19 @@
|
||||
const DEFAULT_PROMPT = ">";
|
||||
|
||||
export default class Console {
|
||||
#prompt: string;
|
||||
|
||||
constructor() {
|
||||
this.#prompt = DEFAULT_PROMPT;
|
||||
}
|
||||
|
||||
ask(question: string): string {
|
||||
const answer = prompt(`${question}\n${this.#prompt} `);
|
||||
|
||||
if (!answer) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return answer;
|
||||
}
|
||||
}
|
10
data/data.ts
Normal file
10
data/data.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export * from "./rooms.ts";
|
||||
|
||||
export interface Item {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface GameData {
|
||||
items: Item[];
|
||||
}
|
3
data/rooms.ts
Normal file
3
data/rooms.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const hall = {
|
||||
items: [{ name: "flashlight", description: "There is a flashlight." }],
|
||||
};
|
44
main.ts
Normal file
44
main.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import Console from "./console.ts";
|
||||
import parseCommand from "./parseCommand.ts";
|
||||
|
||||
async function main() {
|
||||
const c = new Console();
|
||||
const question = "Are you a butthole?";
|
||||
let running = true;
|
||||
let statement = "";
|
||||
|
||||
while (running) {
|
||||
const prompts = `${statement}${question}`;
|
||||
const answer = await c.ask(prompts);
|
||||
|
||||
const { action } = parseCommand(answer);
|
||||
|
||||
statement = "";
|
||||
|
||||
switch (action) {
|
||||
case "quit":
|
||||
running = quit(c);
|
||||
break;
|
||||
|
||||
case "take":
|
||||
break;
|
||||
|
||||
default:
|
||||
statement = "I didn't understand that.\n";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function quit(c: Console): boolean {
|
||||
const confirmQuit = c.ask("Are you sure you want to quit?");
|
||||
|
||||
if (confirmQuit[0] === "y") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
main();
|
11
package.json
11
package.json
@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "detective",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
5
parseCommand.ts
Normal file
5
parseCommand.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export default function parseCommand(command: string) {
|
||||
const [action, target] = command.toLocaleLowerCase().split(" ");
|
||||
|
||||
return { action, target };
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"outDir": "dist",
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
Reference in New Issue
Block a user