import { INVENTORY_X, INVENTORY_Y } from "./const"; import { drawBox } from "./display"; import { getItemsCount, Item } from "./item"; import { Sprite } from "./sprite"; export class Player extends Sprite { private inventory: Item[] = []; addItem(item: Item) { for (const i of this.inventory) { if (i.id === item.id) { i.count += item.count; return; } } this.inventory.push(new Item( item.id, item.count, INVENTORY_X + 1 + this.inventory.length, INVENTORY_Y + 1, )); } hasItem(item: Item) { for (const i of this.inventory) { if (i.id === item.id) { return true; } } return false; } get foundItems() { return this.inventory.length; } override doDraw() { super.doDraw(); drawBox(INVENTORY_X, INVENTORY_Y, getItemsCount(), 1, { fill: [' '], title: 'Inv' }); this.inventory.forEach((item) => { if (item.count > 0) { item.doDraw(); } }); } }