UNPKG

quizz

Version:
89 lines (88 loc) 3.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var AbstractGame_1 = require("../AbstractGame"); var QUESTION_DELAY = 30000; var HINT1_DELAY = 10000; var HINT2_DELAY = 20000; var Trivia = /** @class */ (function (_super) { tslib_1.__extends(Trivia, _super); function Trivia(picker) { var _this = _super.call(this) || this; _this.picker = picker; return _this; } Object.defineProperty(Trivia.prototype, "ready", { get: function () { return this.picker.ready; }, enumerable: true, configurable: true }); Trivia.prototype.start = function (output, over) { this.output = output; this.over = over; this.ask(); }; Trivia.prototype.handleMessage = function (answer, user) { if (this.currentQuestion && this.currentQuestion.check(answer)) { this.output(user + " found the answer: " + this.currentQuestion.answer); delete this.currentQuestion; this.over(user); } }; Trivia.prototype.stop = function () { this.clearTimers(); if (this.currentQuestion) { this.output("The answer was: " + this.currentQuestion.answer); delete this.currentQuestion; } }; Trivia.prototype.ask = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var _a, _b; var _this = this; return tslib_1.__generator(this, function (_c) { switch (_c.label) { case 0: _c.trys.push([0, 2, , 3]); _a = this; return [4 /*yield*/, this.picker.pickQuestion()]; case 1: _a.currentQuestion = _c.sent(); this.output(this.currentQuestion.question); this.qto = setTimeout(function () { return _this.timeout(); }, QUESTION_DELAY); this.h1to = setTimeout(function () { return _this.giveHint(1); }, HINT1_DELAY); this.h2to = setTimeout(function () { return _this.giveHint(2); }, HINT2_DELAY); return [3 /*break*/, 3]; case 2: _b = _c.sent(); this.over(null); return [3 /*break*/, 3]; case 3: return [2 /*return*/]; } }); }); }; Trivia.prototype.giveHint = function (level) { if (level === void 0) { level = 1; } this.output(this.currentQuestion.hint(level)); }; Trivia.prototype.timeout = function () { this.output("Timeout! The answer was: " + this.currentQuestion.answer); delete this.currentQuestion; this.over(null); }; Trivia.prototype.clearTimers = function () { clearTimeout(this.qto); delete this.qto; clearTimeout(this.h1to); delete this.h1to; clearTimeout(this.h2to); delete this.h2to; }; Trivia.title = 'Trivia'; Trivia.rules = 'Answer the questions'; return Trivia; }(AbstractGame_1.AbstractGame)); exports.Trivia = Trivia;