Refactor player and room to support adding effects.

This commit is contained in:
2021-05-25 16:02:06 -07:00
parent b3058097b4
commit ccd4974266
13 changed files with 198 additions and 79 deletions

View File

@ -1,21 +1,21 @@
import { Item } from "./data/data.ts";
import Container from "./Container.ts";
import User from "./User.ts";
import { Effect, Item, VesselProperties } from "./types.ts";
import Vessel from "./Vessel.ts";
export default class Player extends Container {
#user: User;
export default class Player extends Vessel<VesselProperties> {
#effects: Effect<VesselProperties>[];
constructor(items?: Item[]) {
super(items || []);
this.#user = new User();
constructor(items: Item[] = [], effects: Effect<VesselProperties>[] = []) {
super({ items }, { effects: [] });
this.#effects = effects;
}
put(item: Item) {
this.items.push(item);
get effects() {
return this.#effects;
}
look(): string {
const description = super.description(this.items);
const description = super.description(this._properties.items || []);
if (description) {
return `You have ${description}`;
@ -23,4 +23,9 @@ export default class Player extends Container {
return "You have nothing.";
}
}
put(item: Item) {
if (!this._properties.items) this._properties.items = [];
this._properties.items.push(item);
}
}