Created Container parent class. Introduced soem fancy bugs.

This commit is contained in:
2021-05-02 14:44:59 -07:00
parent fbf841b551
commit 8d854945e1
6 changed files with 43 additions and 31 deletions

View File

@ -1,29 +1,27 @@
import { GameData, Item } from "./data/data.ts";
import User from "./User.ts";
import Container from "./Container.ts";
export default class Scene {
#items: Item[];
export default class Scene extends Container {
#user: User;
constructor(gameData: GameData) {
this.#items = gameData.items;
super(gameData.items);
this.#user = new User();
}
async look() {
const description = this.#items
.map(({ description }) => description)
.join(" ");
const description = super.description(this.items);
await this.#user.tell(description);
await this.#user.tell(`There is ${description}`);
}
async take(target: string): Promise<Item | null> {
const idx = this.#items.findIndex(({ name }) => name === target);
const idx = this.items.findIndex(({ name }) => name === target);
if (idx >= 0) {
const item = this.#items[idx];
this.#items.splice(idx, 1);
const item = this.items[idx];
this.items.splice(idx, 1);
await this.#user.tell("Taken.");