stop the party when draw
This commit is contained in:
parent
1831a7ac91
commit
779ce55472
2 changed files with 14 additions and 2 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
14
src/game.ts
14
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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue