From 779ce55472db4d0132766e43a536c9a4751f7d98 Mon Sep 17 00:00:00 2001 From: Didictateur Date: Tue, 25 Mar 2025 22:45:02 +0100 Subject: [PATCH] stop the party when draw --- src/display/dp4.ts | 2 ++ src/game.ts | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/display/dp4.ts b/src/display/dp4.ts index 84ab99f..fbc01cb 100644 --- a/src/display/dp4.ts +++ b/src/display/dp4.ts @@ -37,6 +37,7 @@ function drawFrame() { } function animationLoop(currentTime: number) { + if (!GAME?.isFinished()){ animationFrameId = requestAnimationFrame(animationLoop); const deltaTime = currentTime - lastFrameTime; @@ -44,6 +45,7 @@ function animationLoop(currentTime: number) { lastFrameTime = currentTime - (deltaTime % FRAME_INTERVAL); drawFrame(); + } } function initEventListeners() { diff --git a/src/game.ts b/src/game.ts index f20e757..d87395e 100644 --- a/src/game.ts +++ b/src/game.ts @@ -22,6 +22,7 @@ export class Game { private hasPicked: boolean = false; private hasPlayed: boolean = false; private lastPlayed: number = Date.now(); + private end: boolean = false; // display parameter private BG_RECT = {color: "#007730", x: 0, y: 0, w: 1050, h: 1050}; @@ -64,6 +65,10 @@ export class Game { this.pick(0); } + public isFinished(): boolean { + return this.end; + } + public draw(mp: mousePos) { // background this.staticCtx.clearRect(0, 0, this.cv.width, this.cv.height); @@ -171,8 +176,13 @@ export class Game { let n = Math.floor(this.hands[this.turn].length() * Math.random()); this.discard(this.turn, n); this.hasPlayed = true; - this.checkPon(); - this.canCall = this.canDoAChii().length > 0 || this.canDoAPon(); + if (this.deck.length() <= 0) { + this.end = true; + } + if (!this.isFinished()) { + this.checkPon(); + this.canCall = this.canDoAChii().length > 0 || this.canDoAPon(); + } } } else if (!this.canCall) { // end of his turn if (this.turn === 3) {