Add life and orange power up toggle config
This commit is contained in:
parent
3244ae7046
commit
896347025c
1 changed files with 25 additions and 6 deletions
|
@ -22,6 +22,9 @@ export class Game {
|
|||
this.direction = directions.RIGHT;
|
||||
this.snakeSpeed = this.baseSnakeSpeed = 500;
|
||||
this.lives = 3;
|
||||
this.walls = true;
|
||||
this.life = true;
|
||||
this.orange = true;
|
||||
|
||||
this.world = [];
|
||||
this.score = 0;
|
||||
|
@ -129,8 +132,10 @@ export class Game {
|
|||
main() {
|
||||
try {
|
||||
this.moveSnake();
|
||||
this.lifeGenerator();
|
||||
this.orangeGenerator();
|
||||
if (this.life)
|
||||
this.lifeGenerator();
|
||||
if (this.orange)
|
||||
this.orangeGenerator();
|
||||
this.drawGrid();
|
||||
|
||||
} catch (err) {
|
||||
|
@ -260,7 +265,6 @@ export class Game {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate random coordinates of empty tiles
|
||||
* @returns {[int, int]}
|
||||
|
@ -285,8 +289,11 @@ export class Game {
|
|||
* @param {int} snakeSpeed
|
||||
* @param {int} appleSpeed
|
||||
* @param {int} lives
|
||||
* @param {boolean} walls
|
||||
* @param {boolean} life
|
||||
* @param {boolean} orange
|
||||
*/
|
||||
load({size = [15, 15], snakeSize = 4, direction = directions.RIGHT, snakeSpeed = 500, lives = 3, walls = true} = {}) {
|
||||
load({size = [15, 15], snakeSize = 4, direction = directions.RIGHT, snakeSpeed = 500, lives = 3, walls = true, life = true, orange = true} = {}) {
|
||||
if (size && Array.isArray(size) && size.length === 2 && size.filter(s => typeof s === "number" && s > 0 && s % 1 === 0).length === size.length)
|
||||
this.size = size;
|
||||
else
|
||||
|
@ -312,8 +319,20 @@ export class Game {
|
|||
else
|
||||
throw new InvalidGameOption("lives");
|
||||
|
||||
if (walls && typeof walls === "boolean")
|
||||
this.walls = walls
|
||||
if (typeof walls === "boolean")
|
||||
this.walls = walls;
|
||||
else
|
||||
throw new InvalidGameOption("walls");
|
||||
|
||||
if (typeof life === "boolean")
|
||||
this.life = life;
|
||||
else
|
||||
throw new InvalidGameOption("life");
|
||||
|
||||
if (typeof orange === "boolean")
|
||||
this.orange = orange;
|
||||
else
|
||||
throw new InvalidGameOption("orange");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue