doggo-quest-logic
Version:
The game logic for the Doggo Quest text-based game sample project
52 lines (51 loc) • 1.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Word {
constructor(text, reduced, initialTags) {
this.text = text;
this.reduced = reduced;
this.parent = null;
this.children = [];
this.gameObject = null;
this.tags = initialTags;
}
get tagNames() {
return this.tags;
}
get hasChildren() {
return this.children.length > 0;
}
get isNoun() {
return this.hasTag('Noun');
}
get isDirection() {
return this.hasTag('Direction');
}
get isVerb() {
return this.hasTag('Verb');
}
get isAdverb() {
return this.hasTag('Adverb');
}
hasTag(tagName) {
return this.tags.findIndex(t => t === tagName) >= 0;
}
addTag(tagName) {
if (!this.hasTag(tagName)) {
this.tags.push(tagName);
}
return this;
}
removeTag(tagName) {
const index = this.tags.findIndex(t => t === tagName);
if (index >= 0) {
this.tags.splice(index, 1);
}
return this;
}
addChild(word) {
this.children.push(word);
return this;
}
}
exports.Word = Word;