diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 5ef05c0..0000000 --- a/.eslintrc +++ /dev/null @@ -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"] -} diff --git a/.gitignore b/.gitignore index a34433f..19e2baa 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ .DS_Store # Folders -dist/* -node_modules/* \ No newline at end of file +.vscode diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index c959087..0000000 --- a/.prettierrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "useTabs": true -} diff --git a/Scene.ts b/Scene.ts new file mode 100644 index 0000000..d06e734 --- /dev/null +++ b/Scene.ts @@ -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; + } +} diff --git a/console.ts b/console.ts new file mode 100644 index 0000000..904cc14 --- /dev/null +++ b/console.ts @@ -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; + } +} diff --git a/data/data.ts b/data/data.ts new file mode 100644 index 0000000..5e1be6b --- /dev/null +++ b/data/data.ts @@ -0,0 +1,10 @@ +export * from "./rooms.ts"; + +export interface Item { + name: string; + description: string; +} + +export interface GameData { + items: Item[]; +} diff --git a/data/rooms.ts b/data/rooms.ts new file mode 100644 index 0000000..724301b --- /dev/null +++ b/data/rooms.ts @@ -0,0 +1,3 @@ +export const hall = { + items: [{ name: "flashlight", description: "There is a flashlight." }], +}; diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..2898bd8 --- /dev/null +++ b/main.ts @@ -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(); diff --git a/package.json b/package.json deleted file mode 100644 index ac6671f..0000000 --- a/package.json +++ /dev/null @@ -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" -} diff --git a/parseCommand.ts b/parseCommand.ts new file mode 100644 index 0000000..07174ce --- /dev/null +++ b/parseCommand.ts @@ -0,0 +1,5 @@ +export default function parseCommand(command: string) { + const [action, target] = command.toLocaleLowerCase().split(" "); + + return { action, target }; +} diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 102bb42..0000000 --- a/tsconfig.json +++ /dev/null @@ -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"] -}