From 111167b60000e1c7c4187a22cc4228e7fb5f88d3 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Sat, 18 Jul 2026 18:03:56 +0300 Subject: [PATCH] =?UTF-8?q?feat(game):=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=83=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D0=BD=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/game.js b/src/game.js index 71df444..f37876d 100644 --- a/src/game.js +++ b/src/game.js @@ -25,6 +25,7 @@ export class Game { constructor(levels) { this.livesAmount = 3; this.status = 'in_process'; + this.levels = levels; this.currentLevel = 0; this.maxLevel = levels.length - 1; @@ -36,7 +37,7 @@ export class Game { -1 * BALL_SPEED * Math.sin(toRadians(BALL_INITIAL_ANGLE)), ); this.paddle = new Paddle(0, CONTAINER_HEIGHT - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT); - this.bricks = layBricks(levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT); + this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT); } /** @@ -47,6 +48,7 @@ export class Game { if (this.status !== 'in_process') { return; } + tick(this, CONTAINER_WIDTH, CONTAINER_HEIGHT, deltaTime); if (this.ball.isOut) { @@ -57,12 +59,28 @@ export class Game { } else { this.ball.reset(); } + + return; } const isAnyBrickAlive = this.bricks.some((brick) => brick.alive); if (!isAnyBrickAlive) { - this.status = 'completed'; + this.currentLevel += 1; + + if (this.currentLevel <= this.maxLevel) { + this._proceedToNextLevel(); + } else { + this.status = 'completed'; + } } } + + /** + * Запускает переход на новый уровень, возвращает мяч в дефоотное положение и отрисовывает кирпичи по карте уровня. + */ + _proceedToNextLevel() { + this.ball.reset(); + this.bricks = layBricks(this.levels[this.currentLevel], BRICK_WIDTH, BRICK_HEIGHT); + } }