Skip to content
Open
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
20 changes: 19 additions & 1 deletion Games/Tetris/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ function renderGame(){
renderPiece();
}



document.addEventListener("keydown",function(e){
let key = e.key;
if(key == "ArrowDown"){
Expand All @@ -227,4 +229,20 @@ document.addEventListener("keydown",function(e){
}else if(key == "ArrowUp"){
rotate();
}
})
})


//Sahu: script.js β€” add this after your other listeners
document.getElementById('start-button').addEventListener('click', () => {
// reset core state, same as on game over
grid = generateGrid(); // fresh empty grid
score = 0; // reset score
fallingPieceObj = null; // force a new random piece in next tick
scoreboard.innerHTML = "Score: " + score;

// optional: clear the canvas immediately
ctx.clearRect(0, 0, canvas.width, canvas.height);

// redraw the empty board
renderGame();
})