Compare commits

...
2 Commits
Author SHA1 Message Date
ilia a16f316b13 Merge pull request 'feat: Добавлено сообщение об окончании игры и кнопка перезагрузки' (#7) from feature/notifications into main
Build and push / build (push) Successful in 39s
Reviewed-on: #7
2026-07-20 07:27:23 +00:00
Ilia Mashkov a11ab8cd5d feat: Добавлено сообщение об окончании игры и кнопка перезагрузки
Build and push / build (push) Skipped
Build and push / build (pull_request) Successful in 41s
2026-07-20 10:22:03 +03:00
2 changed files with 46 additions and 7 deletions
+17 -7
View File
@@ -18,21 +18,14 @@ import { Game } from './game';
import { createGameView, managePerkViewsLifetime, rebuildBrickViews, syncronizeViewsWithGame } from './view'; import { createGameView, managePerkViewsLifetime, rebuildBrickViews, syncronizeViewsWithGame } from './view';
(async () => { (async () => {
// Create a new application
const app = new Application(); const app = new Application();
// Initialize the application
await app.init({ background: '#1099bb', width: CONTAINER_WIDTH, height: CONTAINER_HEIGHT }); await app.init({ background: '#1099bb', width: CONTAINER_WIDTH, height: CONTAINER_HEIGHT });
// Append the application canvas to the document body
document.body.appendChild(app.canvas); document.body.appendChild(app.canvas);
// Create and add a container to the stage
const container = new Container({ const container = new Container({
eventMode: 'static', eventMode: 'static',
hitArea: app.screen, hitArea: app.screen,
}); });
container.x = 0; container.x = 0;
container.y = 0; container.y = 0;
@@ -73,5 +66,22 @@ import { createGameView, managePerkViewsLifetime, rebuildBrickViews, syncronizeV
} }
managePerkViewsLifetime(views, game, container, textures); managePerkViewsLifetime(views, game, container, textures);
syncronizeViewsWithGame(views, game); syncronizeViewsWithGame(views, game);
if (game.status === 'over' || game.status === 'completed') {
showEndScreen(game.status === 'completed' ? 'Победа!' : 'Игра окончена!');
app.ticker.stop();
}
}); });
})(); })();
/**
* Показывает финальный экран с сообщением и кнопкой рестарта (перезагрузка страницы).
* @param {string} message текст результата игры
*/
function showEndScreen(message) {
const overlay = document.createElement('div');
overlay.className = 'end-screen';
overlay.innerHTML = `<p>${message}</p><button class="button" type="button">Начать заново</button>`;
overlay.querySelector('button').addEventListener('click', () => location.reload());
document.body.appendChild(overlay);
}
+29
View File
@@ -10,3 +10,32 @@ canvas {
display: block; display: block;
object-fit: contain; object-fit: contain;
} }
.end-screen {
position: fixed;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 1rem;
background: rgba(0, 0, 0, 0.6);
color: #fff;
font-size: 3rem;
font-family: sans-serif;
font-weight: 700;
}
.end-screen button {
color: #ffffff;
font-size: 1.5rem;
font-family: sans-serif;
padding: 0.5rem 1.5rem;
cursor: pointer;
transition: all 0.2s ease-out;
}
.end-screen button:hover {
color: #ffffff88;
}