uradibou/src/games/smartMonday.js

36 lines
1,023 B
JavaScript

import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js";
import { TimedGame } from "./timedGame";
import { KeyBoardListener } from "../common";
export class SmartMonday extends TimedGame {
constructor(ticker) {
super(10000, ticker);
this._goal = 100 * this._difficulty; // number of characters
this.timeout = 1000 * (this._goal / 10); // 10 chars per second
this._currentString = "";
this._keyEventHandle = undefined;
}
reset() {
super.reset();
this._currentString = "";
}
start() {
super.start();
this._keyEventHandle = KeyBoardListener.onKeyDown((event) => {
this._currentString += event.key;
console.log("current text", this._currentString);
if (this._currentString.length >= this._goal) {
this.end(true);
}
});
}
end(status) {
super.end(status);
KeyBoardListener.offKeyDown(this._keyEventHandle);
}
}