refactor(tick): В условия добавлены return для отсеивания лишних операций

This commit is contained in:
Ilia Mashkov
2026-07-18 13:32:54 +03:00
parent 274cc93c55
commit 562805b35c
2 changed files with 5 additions and 3 deletions
+3 -1
View File
@@ -41,12 +41,14 @@ export function tick(game, containerWidth, containerHeight, deltaTime) {
if (ball.x <= leftBoundary || ball.x >= rightBoundary) {
ball.x = ball.x <= leftBoundary ? leftBoundary : rightBoundary;
ball.horizontalSpeed *= -1;
return;
}
// Не даем мячу выйти за границу стены сверху и меняем направление
if (ball.y <= topBoundary) {
ball.y = topBoundary;
ball.verticalSpeed *= -1;
return;
}
// Проверяем выход за границу стены снизу
@@ -84,7 +86,7 @@ export function tick(game, containerWidth, containerHeight, deltaTime) {
ball.horizontalSpeed *= directions[0];
ball.verticalSpeed *= directions[1];
brick.kill();
break;
return;
}
}
}
+2 -2
View File
@@ -50,7 +50,7 @@ describe('tick', () => {
const game = new Game(1, 1);
const brick = game.bricks[0][0];
game.ball.x = brick.x + 1;
game.ball.x = brick.x + game.ball.radius + 1;
game.ball.y = brick.y + brick.height + game.ball.radius + 1;
game.ball.horizontalSpeed = 0;
game.ball.verticalSpeed = -10;
@@ -65,7 +65,7 @@ describe('tick', () => {
const game = new Game(2, 1);
const [firstBrick, secondBrick] = game.bricks[0];
game.ball.x = firstBrick.x + 1;
game.ball.x = firstBrick.x + game.ball.radius + 1;
game.ball.y = firstBrick.y + firstBrick.height + game.ball.radius + 1;
game.ball.horizontalSpeed = 0;
game.ball.verticalSpeed = -10;