Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<main>
<section id="game-area">
<canvas id="gameBoard" width="400" height="400"></canvas>
<div id="pause-overlay" aria-hidden="true">
<div class="pause-text">GAME PAUSED</div>
</div>
<div id="game-stats">
<span id="scoreBox">Score: <span id="score">0</span></span>
<span id="bestScoreBox"> </span>
Expand Down
21 changes: 21 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,27 @@ function resetGame() {
const startBtn = document.getElementById('startBtn');
const pauseBtn = document.getElementById('pauseBtn');
const resetBtn = document.getElementById('resetBtn');
const pauseOverlay = document.getElementById('pause-overlay');

function setPauseOverlay(visible) {
if (!pauseOverlay) return;
if (visible) {
pauseOverlay.classList.add('show');
pauseOverlay.setAttribute('aria-hidden', 'false');
} else {
pauseOverlay.classList.remove('show');
pauseOverlay.setAttribute('aria-hidden', 'true');
}
}


startBtn.onclick = () => {
if (!gameRunning) {
if (snake.length > 1 || score > 0 || direction.x !== 0 || direction.y !== 0) {
resetGame();
}
// Ensure overlay is hidden when starting/resuming play
setPauseOverlay(false);
gameRunning = true;
pauseBtn.textContent = 'Pause';
pauseBtn.disabled = false;
Expand All @@ -417,10 +431,14 @@ pauseBtn.onclick = () => {
gameRunning = false;
pauseBtn.textContent = 'Resume';
document.body.classList.remove('game-active');
// Show overlay immediately when paused
setPauseOverlay(true);
} else {
gameRunning = true;
pauseBtn.textContent = 'Pause';
document.body.classList.add('game-active');
// Hide overlay when resuming
setPauseOverlay(false);
if (!animationId) loop();
}
};
Expand All @@ -429,6 +447,7 @@ resetBtn.onclick = () => {
pauseBtn.textContent = 'Pause';
pauseBtn.disabled = true;
resetBtn.disabled = true;
setPauseOverlay(false);
resetGame();
};

Expand All @@ -442,4 +461,6 @@ window.onload = function () {
loadBestScore();
initGameVars();
draw();
// Ensure pause overlay hidden on load
setPauseOverlay(false);
};
41 changes: 41 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,45 @@ footer {
max-width: 95vw;
max-height: 89vw;
}
}

/* Pause overlay that appears above the game canvas when paused */
#pause-overlay {
position: absolute;
/* Place overlay directly over the canvas (canvas is centered) */
top: 22px; /* matches #game-area padding-top */
left: 50%;
transform: translateX(-50%);
width: 400px;
height: 400px;
max-width: 96vw;
max-height: 70vw;
border-radius: 11px;
display: flex;
align-items: center;
justify-content: center;
background: rgba(0, 0, 0, 0.6);
color: var(--white);
font-size: 34px;
font-weight: 800;
text-align: center;
letter-spacing: 1px;
z-index: 200;
opacity: 0;
pointer-events: none;
transition: opacity .18s ease;
}

#pause-overlay.show {
opacity: 1;
pointer-events: auto; /* block interactions when paused */
}

#pause-overlay .pause-text {
text-shadow: 0 4px 18px rgba(0,0,0,0.6);
font-family: 'Inter', Arial, sans-serif;
}

@media (max-width:520px) {
#pause-overlay { top: 16px; }
}