feat: Добавлено сообщение об окончании игры и кнопка перезагрузки
Build and push / build (push) Skipped
Build and push / build (pull_request) Successful in 41s
Build and push / build (push) Skipped
Build and push / build (pull_request) Successful in 41s
This commit is contained in:
+17
-7
@@ -18,21 +18,14 @@ import { Game } from './game';
|
||||
import { createGameView, managePerkViewsLifetime, rebuildBrickViews, syncronizeViewsWithGame } from './view';
|
||||
|
||||
(async () => {
|
||||
// Create a new application
|
||||
const app = new Application();
|
||||
|
||||
// Initialize the application
|
||||
await app.init({ background: '#1099bb', width: CONTAINER_WIDTH, height: CONTAINER_HEIGHT });
|
||||
|
||||
// Append the application canvas to the document body
|
||||
document.body.appendChild(app.canvas);
|
||||
|
||||
// Create and add a container to the stage
|
||||
const container = new Container({
|
||||
eventMode: 'static',
|
||||
hitArea: app.screen,
|
||||
});
|
||||
|
||||
container.x = 0;
|
||||
container.y = 0;
|
||||
|
||||
@@ -73,5 +66,22 @@ import { createGameView, managePerkViewsLifetime, rebuildBrickViews, syncronizeV
|
||||
}
|
||||
managePerkViewsLifetime(views, game, container, textures);
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user