CS-Coursework/websites/Typing/screens/screenmanager.js

41 lines
960 B
JavaScript
Raw Normal View History

2022-11-28 11:04:49 +00:00
/**
* @file This file provides the screen manager class, with the necassary code to switch between screen classes
* @author Arlo Filley
*
* TODO:
* - implement transitions between screens in a more fluid way
*/
/**
* This class provides the ScreenManager class stores the current screen
* and provides the getters and setters necessary to switch between screen classes
* easily
*/
2022-10-10 14:05:09 +01:00
class ScreenManager {
constructor() {
2022-10-11 09:45:40 +01:00
this.textbox;
this.timer;
this.screen;
2022-10-10 14:05:09 +01:00
}
draw() {
2022-10-11 09:45:40 +01:00
this.screen.draw();
}
setScreen(pScreen) {
this.screen = pScreen;
}
getScreen() {
return this.screen;
2022-10-10 14:05:09 +01:00
}
2022-11-11 13:04:13 +00:00
letterTyped(key) {
let methods = Object.getOwnPropertyNames(Object.getPrototypeOf(this.screen));
for (let i = 0; i < methods.length; i++) {
if (methods[i] === "letterTyped") {
this.screen.letterTyped(key)
}
}
}
2022-10-10 14:05:09 +01:00
}