From 448904d12ae462e597f055b09778c60f139ffd9f Mon Sep 17 00:00:00 2001 From: Sukalyan Sahu Date: Tue, 6 Jan 2026 18:51:31 +0530 Subject: [PATCH 1/2] New game start on Start New Game button click --- Games/Tetris/script.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Games/Tetris/script.js b/Games/Tetris/script.js index 3445b2974f..9ff77657f6 100644 --- a/Games/Tetris/script.js +++ b/Games/Tetris/script.js @@ -216,6 +216,8 @@ function renderGame(){ renderPiece(); } + + document.addEventListener("keydown",function(e){ let key = e.key; if(key == "ArrowDown"){ @@ -227,4 +229,20 @@ document.addEventListener("keydown",function(e){ }else if(key == "ArrowUp"){ rotate(); } -}) \ No newline at end of file +}) + + +//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(); +}) From 1d52465b4c873ee8355db042870095874c6628d0 Mon Sep 17 00:00:00 2001 From: Sukalyan Sahu Date: Thu, 22 Jan 2026 18:34:22 +0530 Subject: [PATCH 2/2] Added levels - Easy, Medium and Difficult --- Games/Tetris/index.html | 60 +++++++++++++++++++++++++++++++++++++++++ Games/Tetris/script.js | 29 +++++++++++++++++++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/Games/Tetris/index.html b/Games/Tetris/index.html index ae326440cd..dc8bf70679 100644 --- a/Games/Tetris/index.html +++ b/Games/Tetris/index.html @@ -17,6 +17,66 @@

TETRIS

Score: 0

+ + +
+ + + + +
diff --git a/Games/Tetris/script.js b/Games/Tetris/script.js index 9ff77657f6..88891acc04 100644 --- a/Games/Tetris/script.js +++ b/Games/Tetris/script.js @@ -59,7 +59,7 @@ let grid = generateGrid(); let fallingPieceObj = null; let score = 0; -setInterval(newGameState,500); +setInterval(newGameState,1200); function newGameState(){ checkGrid(); if(!fallingPieceObj){ @@ -246,3 +246,30 @@ document.getElementById('start-button').addEventListener('click', () => { // redraw the empty board renderGame(); }) + +document.addEventListener('DOMContentLoaded', () => { + const levelButtons = document.querySelectorAll('#level-selector button'); + levelButtons.forEach(button => { + button.addEventListener('click', () => { + levelButtons.forEach(btn => btn.classList.remove('active')); + button.classList.add('active'); + }); + }); +}); + +let gameInterval; // Variable to store the interval ID + +document.getElementById('easy-button').addEventListener('click', function() { + clearInterval(gameInterval); // Clear any existing interval + gameInterval = setInterval(newGameState, 1200); // Set new interval for easy level +}); + +document.getElementById('medium-button').addEventListener('click', function() { + clearInterval(gameInterval); // Clear any existing interval + gameInterval = setInterval(newGameState, 900); // Set new interval for medium level +}); + +document.getElementById('difficult-button').addEventListener('click', function() { + clearInterval(gameInterval); // Clear any existing interval + gameInterval = setInterval(newGameState, 100); // Set new interval for difficult level +});