added win popup

This commit is contained in:
Nathan DECHER
2020-04-04 22:59:50 +02:00
parent 76f1765be7
commit 3997e94a68
4 changed files with 192 additions and 12 deletions
+8 -5
View File
@@ -84,7 +84,7 @@ class SnekGame {
// get our canvas, like, if we want to actually draw
this.canvas=canvas;
this.ctx=canvas.getContext('2d');
// load the custom rules
this.rules=Object.assign({
fruitRegrow: true,
@@ -160,7 +160,7 @@ class SnekGame {
putTileAnim(x, y, fire);
break;
case HOLE:
case HOLE:
case HOLE_S: {
putTile(x, y, hole.base);
let adj=checkAdj(x, y);
@@ -293,6 +293,9 @@ class SnekGame {
([x, y]) => !(x==head[0] && y==head[1])
);
// increase score
this.score++;
// custom rules
if(this.rules.fruitRegrow) {
const emptyCells=this.world
@@ -301,7 +304,7 @@ class SnekGame {
.map(
(r, y) => r==EMPTY?[x,y]:null
).filter(
a => a
a => a
)
).flat();
const cell=emptyCells[Math.floor(Math.random()*emptyCells.length)];
@@ -409,9 +412,9 @@ class SnekGame {
this.firstStep=Date.now();
this.tickId=0;
this.playing=true;
this.score=0;
requestAnimationFrame(() => this.tick());
}
}
module.exports=SnekGame;
return SnekGame;
return module.exports=SnekGame;