Add room description.
This commit is contained in:
@ -15,7 +15,8 @@ export default class Container {
|
|||||||
.map(({ name }, i) => {
|
.map(({ name }, i) => {
|
||||||
let anItem = `${vowels.includes(name[0]) ? "an" : "a"} ${name}`;
|
let anItem = `${vowels.includes(name[0]) ? "an" : "a"} ${name}`;
|
||||||
|
|
||||||
if (i + 1 === items.length) {
|
// if we have more than one item, and this is the last item...
|
||||||
|
if (i > 1 && i + 1 === items.length) {
|
||||||
anItem = `and ${anItem}`;
|
anItem = `and ${anItem}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
Scene.ts
17
Scene.ts
@ -1,23 +1,24 @@
|
|||||||
import { GameData, Item } from "./data/data.ts";
|
import { GameData, Item } from "./data/data.ts";
|
||||||
import User from "./User.ts";
|
|
||||||
import Container from "./Container.ts";
|
import Container from "./Container.ts";
|
||||||
|
|
||||||
export default class Scene extends Container {
|
export default class Scene extends Container {
|
||||||
#user: User;
|
#roomDescription: string;
|
||||||
|
|
||||||
constructor(gameData: GameData) {
|
constructor(gameData: GameData) {
|
||||||
super(gameData.items);
|
super(gameData.items);
|
||||||
this.#user = new User();
|
|
||||||
|
this.#roomDescription = gameData.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
look(): string {
|
look(): string {
|
||||||
const description = super.description(this.items);
|
const itemsDescription = super.description(this.items);
|
||||||
|
let description = this.#roomDescription;
|
||||||
|
|
||||||
if (description) {
|
if (itemsDescription) {
|
||||||
return `There is ${description}`;
|
description += `\n\nThere is ${itemsDescription}`;
|
||||||
} else {
|
|
||||||
return "There is nothing around...";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
get(target: string): Item | null {
|
get(target: string): Item | null {
|
||||||
|
@ -5,5 +5,6 @@ export interface Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface GameData {
|
export interface GameData {
|
||||||
|
description: string;
|
||||||
items: Item[];
|
items: Item[];
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
export const hall = {
|
import { GameData } from "./data.ts";
|
||||||
|
|
||||||
|
export const hall: GameData = {
|
||||||
|
description:
|
||||||
|
"You are standing in a big hall. There's lots of nooks, crannies, and" +
|
||||||
|
"room for general testing. Aw yeah... sweet testing!",
|
||||||
items: [{ name: "flashlight" }],
|
items: [{ name: "flashlight" }],
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user