UNPKG

doggo-quest-logic

Version:

The game logic for the Doggo Quest text-based game sample project

61 lines (60 loc) 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Word_1 = require("./Word"); class Sentence { constructor() { this.text = ''; this.words = []; } get verbWord() { if (this.words.length <= 0 || !this.words[0].isVerb) { return undefined; } return this.words[0]; } get verb() { const word = this.verbWord; if (word) { return word.reduced; } return undefined; } get target() { if (this.words.length > 1) { for (const word of this.words) { if (word.isNoun) { return word; } } } return undefined; } get rootWords() { const roots = []; for (const word of this.words) { if (!word.parent) { roots.push(word); } } return roots; } addWord(word) { this.words.push(word); } validate() { if (this.words.length <= 0) { return 'I\'m sorry, did you want to do something?'; } if (!this.words[0].isVerb) { return 'Your command must start with a verb. For example: \'Bark at the squirrel\''; } if (this.words.filter(w => w.isVerb).length > 1) { return 'Your command cannot have more than one verb'; } return undefined; } assumeVerb(verb) { this.words = [new Word_1.Word(verb, verb, ['Verb']), ...this.words]; } } exports.Sentence = Sentence;