123456789101112131415161718192021222324252627 |
- import { FiniteStateMachine } from "../libraries/FiniteStateMachine.js";
- import STATE from "./states/index.js";
- export class GameView {
- constructor(viewElement) {
- this.element = viewElement
- this.stateMachine = new FiniteStateMachine();
- this.stateMachine.registerState("mainmenu", new STATE.MainMenuState(this))
- this.stateMachine.registerState("matchthree", new STATE.MatchThreeState(this))
- this.stateMachine.registerState("matchthree2", new STATE.MatchThreeState2(this))
- this.stateMachine.registerState("credits", new STATE.CreditsState(this))
- }
- async init(scaledCanvas) {
- this.stateMachine.getAllStates().forEach(state => { state.init(scaledCanvas) })
- this.stateMachine.setCurrentState("mainmenu");
- this.scaledCanvas = scaledCanvas
- this.stateMachine.getCurrentState().enter();
- }
- draw(ctx, scaledCanvas) {
- this.stateMachine.getCurrentState().draw(ctx, scaledCanvas);
- }
- update(delta) {
- this.stateMachine.getCurrentState().update(delta);
- }
- }
|