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) {
|
function animationLoop(currentTime: number) {
|
||||||
|
if (!GAME?.isFinished()){
|
||||||
animationFrameId = requestAnimationFrame(animationLoop);
|
animationFrameId = requestAnimationFrame(animationLoop);
|
||||||
|
|
||||||
const deltaTime = currentTime - lastFrameTime;
|
const deltaTime = currentTime - lastFrameTime;
|
||||||
|
|
@ -44,6 +45,7 @@ function animationLoop(currentTime: number) {
|
||||||
|
|
||||||
lastFrameTime = currentTime - (deltaTime % FRAME_INTERVAL);
|
lastFrameTime = currentTime - (deltaTime % FRAME_INTERVAL);
|
||||||
drawFrame();
|
drawFrame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initEventListeners() {
|
function initEventListeners() {
|
||||||
|
|
|
||||||
10
src/game.ts
10
src/game.ts
|
|
@ -22,6 +22,7 @@ export class Game {
|
||||||
private hasPicked: boolean = false;
|
private hasPicked: boolean = false;
|
||||||
private hasPlayed: boolean = false;
|
private hasPlayed: boolean = false;
|
||||||
private lastPlayed: number = Date.now();
|
private lastPlayed: number = Date.now();
|
||||||
|
private end: boolean = false;
|
||||||
|
|
||||||
// display parameter
|
// display parameter
|
||||||
private BG_RECT = {color: "#007730", x: 0, y: 0, w: 1050, h: 1050};
|
private BG_RECT = {color: "#007730", x: 0, y: 0, w: 1050, h: 1050};
|
||||||
|
|
@ -64,6 +65,10 @@ export class Game {
|
||||||
this.pick(0);
|
this.pick(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isFinished(): boolean {
|
||||||
|
return this.end;
|
||||||
|
}
|
||||||
|
|
||||||
public draw(mp: mousePos) {
|
public draw(mp: mousePos) {
|
||||||
// background
|
// background
|
||||||
this.staticCtx.clearRect(0, 0, this.cv.width, this.cv.height);
|
this.staticCtx.clearRect(0, 0, this.cv.width, this.cv.height);
|
||||||
|
|
@ -171,9 +176,14 @@ export class Game {
|
||||||
let n = Math.floor(this.hands[this.turn].length() * Math.random());
|
let n = Math.floor(this.hands[this.turn].length() * Math.random());
|
||||||
this.discard(this.turn, n);
|
this.discard(this.turn, n);
|
||||||
this.hasPlayed = true;
|
this.hasPlayed = true;
|
||||||
|
if (this.deck.length() <= 0) {
|
||||||
|
this.end = true;
|
||||||
|
}
|
||||||
|
if (!this.isFinished()) {
|
||||||
this.checkPon();
|
this.checkPon();
|
||||||
this.canCall = this.canDoAChii().length > 0 || this.canDoAPon();
|
this.canCall = this.canDoAChii().length > 0 || this.canDoAPon();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (!this.canCall) { // end of his turn
|
} else if (!this.canCall) { // end of his turn
|
||||||
if (this.turn === 3) {
|
if (this.turn === 3) {
|
||||||
this.turn = 0;
|
this.turn = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue