GameView.js 1.1 KB

123456789101112131415161718192021222324252627
  1. import { FiniteStateMachine } from "../libraries/FiniteStateMachine.js";
  2. import STATE from "./states/index.js";
  3. export class GameView {
  4. constructor(viewElement) {
  5. this.element = viewElement
  6. this.stateMachine = new FiniteStateMachine();
  7. this.stateMachine.registerState("mainmenu", new STATE.MainMenuState(this))
  8. this.stateMachine.registerState("matchthree", new STATE.MatchThreeState(this))
  9. this.stateMachine.registerState("matchthree2", new STATE.MatchThreeState2(this))
  10. this.stateMachine.registerState("credits", new STATE.CreditsState(this))
  11. }
  12. async init(scaledCanvas) {
  13. this.stateMachine.getAllStates().forEach(state => { state.init(scaledCanvas) })
  14. this.stateMachine.setCurrentState("mainmenu");
  15. this.scaledCanvas = scaledCanvas
  16. this.stateMachine.getCurrentState().enter();
  17. }
  18. draw(ctx, scaledCanvas) {
  19. this.stateMachine.getCurrentState().draw(ctx, scaledCanvas);
  20. }
  21. update(delta) {
  22. this.stateMachine.getCurrentState().update(delta);
  23. }
  24. }