JSFiddle - React, Tailwind, and code Playground
by MegaScience
JavaScript
function GameManager(InputManager) {
this.inputManager = new InputManager;
this.inputManager.on("move", this.move.bind(this));
this.inputManager.on("restart", this.restart.bind(this));
this.inputManager.on("keepPlaying", this.keepPlaying.bind(this));
}
GameManager.prototype.move = function (direction) {
var self = this;
console.log("Move");
return this;
};
GameManager.prototype.restart = function (direction) {
var self = this;
console.log("Restart");
return this;
};
GameManager.prototype.keepPlaying = function (direction) {
var self = this;
console.log("Keep Playing");
return this;
};
if(true) {
let tempKeepPlaying = GameManager.prototype.keepPlaying;
GameManager.prototype.keepPlaying = function (thisArg) {
console.log("calling a function");
if(GameManager.prototype.keepPlaying.callee !== GameManager.prototype.keepPlaying.caller){
var args = Array.prototype.slice.call(arguments, 1);
tempKeepPlaying.bind(thisArg, args)();}
else {return thisArg;}
};
}
function KeyboardInputManager() {
this.events = {};
if (window.navigator.msPointerEnabled) {
//Internet Explorer 10 style
this.eventTouchstart = "MSPointerDown";
this.eventTouchmove = "MSPointerMove";
this.eventTouchend = "MSPointerUp";
} else {
this.eventTouchstart = "touchstart";
this.eventTouchmove = "touchmove";
this.eventTouchend = "touchend";
}
}
KeyboardInputManager.prototype.on = function (event, callback) {
console.log(callback());
if (!this.events[event]) {
this.events[event] = [];
}
this.events[event].push(callback);
};
new GameManager(KeyboardInputManager);