added win popup
This commit is contained in:
+8
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user