snake: add stashed changes

This commit is contained in:
Trianta 2024-11-05 17:29:07 -06:00
parent 457c7a22fa
commit 7f23f4a40c

View File

@ -68,12 +68,8 @@ class SnakeCore {
this.width = 25;
this.height = 15;
this.board = [];
for (let i = 0; i < this.height; i++) {
for (let i = 0; i < this.height; i++)
this.board.push(new Array(this.width));
for (let j = 0; j < this.width; j++) {
this.board[i][j] = 0;
}
}
this.body = [];
this.gameover = false;
this.foodAte = true;
@ -86,19 +82,22 @@ class SnakeCore {
}
reset() {
snake.gameover = false;
snake.foodAte = true;
this.gameover = false;
this.foodAte = true;
for (let i = 0; i < this.height; i++) {
for (let j = 0; j < this.width; j++) {
this.board[i][j] = 0;
}
}
snake.context.fillStyle = "black";
for (let i = 0; i < snake.height; i++) {
for (let j = 0; j < snake.width; j++) {
snake.context.fillRect(j * snake.grid, i * snake.grid, snake.grid, snake.grid);
}
}
while (this.body.length > 0)
this.body.pop();
this.startRandom();
this.foodRegen();
this.draw();
}
startRandom() {
this.body.push(new Point(Math.floor(Math.random() * this.width), Math.floor(Math.random() * this.height)));
}
foodRegen() {