From bec4d6949d6179d0a2b316f825ef8ae3ad1a58ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vitor=20Maia=20Ribeiro?= Date: Sat, 10 Oct 2026 19:56:11 -0300 Subject: [PATCH 1/7] feat: add quick restart confirmation on R key --- inde.html | 66 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/inde.html b/inde.html index 87e71f8..a1b8417 100644 --- a/inde.html +++ b/inde.html @@ -68,7 +68,7 @@ // game constants //------------------------------------------------------------------------- - var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40 }, + var KEY = { ESC: 27, SPACE: 32, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, R: 82 }, DIR = { UP: 0, RIGHT: 1, DOWN: 2, LEFT: 3, MIN: 0, MAX: 3 }, stats = new Stats(), canvas = get('canvas'), @@ -214,29 +214,61 @@ } function keydown(ev) { - var handled = false; - if (playing) { - switch(ev.keyCode) { - case KEY.LEFT: actions.push(DIR.LEFT); handled = true; break; - case KEY.RIGHT: actions.push(DIR.RIGHT); handled = true; break; - case KEY.UP: actions.push(DIR.UP); handled = true; break; - case KEY.DOWN: actions.push(DIR.DOWN); handled = true; break; - case KEY.ESC: lose(); handled = true; break; - case KEY.SPACE: pause(); handled = true; break; + var handled = false; + + if (document.activeElement && + (document.activeElement.tagName === 'INPUT' || + document.activeElement.tagName === 'TEXTAREA' || + document.activeElement.isContentEditable)) { + return; } - } - else if (ev.keyCode == KEY.SPACE) { - if(paused) { + + if (ev.keyCode == KEY.LEFT || ev.keyCode == KEY.RIGHT || ev.keyCode == KEY.UP || ev.keyCode == KEY.DOWN) { + if (!paused) { + switch (ev.keyCode) { + case KEY.LEFT: actions.push(DIR.LEFT); handled = true; break; + case KEY.RIGHT: actions.push(DIR.RIGHT); handled = true; break; + case KEY.UP: actions.push(DIR.UP); handled = true; break; + case KEY.DOWN: actions.push(DIR.DOWN); handled = true; break; + case KEY.ESC: lose(); handled = true; break; + case KEY.SPACE: pause(); handled = true; break; + case KEY.R: requestRestart(); handled = true; break; + } + } + } + else if (ev.keyCode == KEY.SPACE) { + if (paused) { restart(); handled = true; - }else{ + } else { play(); handled = true; } + } + else if (ev.keyCode == KEY.R) { + requestRestart(); + handled = true; + } + + if (handled) + ev.preventDefault(); + } + + // Função de Reinicio Rápido do Jogo (Quick-resart) + function requestRestart() { + if (!playing && !paused) return; + + if (window.confirm('Tem certeza que deseja reiniciar a partida?')) { + restartGame(); + } + } + + function restartGame() { + reset(); + hide('start'); + paused = false; + playing = true; } - if (handled) - ev.preventDefault(); // prevent arrow keys from scrolling the page (supported in IE9+ and all other browsers) - } //------------------------------------------------------------------------- // GAME LOGIC From e1b385356ba0c56bc358407e1b94cc396e0cc899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vitor=20Maia=20Ribeiro?= Date: Sat, 10 Oct 2026 20:06:10 -0300 Subject: [PATCH 2/7] fix: prevent Space from restarting active game --- inde.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/inde.html b/inde.html index a1b8417..6762167 100644 --- a/inde.html +++ b/inde.html @@ -239,11 +239,13 @@ else if (ev.keyCode == KEY.SPACE) { if (paused) { restart(); - handled = true; + } else if (playing) { + pause(); } else { play(); - handled = true; } + + handled = true; } else if (ev.keyCode == KEY.R) { requestRestart(); From 81196f2226f4a03fbe57a5098e0297da55a62f9b Mon Sep 17 00:00:00 2001 From: Emilly Jullyane de Morais Silva Date: Sun, 11 Oct 2026 00:31:35 -0300 Subject: [PATCH 3/7] feat: adiciona e atualiza score record --- inde.html | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/inde.html b/inde.html index 87e71f8..437c161 100644 --- a/inde.html +++ b/inde.html @@ -97,6 +97,8 @@ rows, // number of completed rows in the current game step; // how long before current piece drops by 1 row + var highScore = Number(localStorage.getItem('highScore')) || 0; + //------------------------------------------------------------------------- // tetris pieces // @@ -245,7 +247,15 @@ function play() { hide('start'); reset(); paused = false; playing = true; } function pause() {show('start'); paused = true; playing = false;} function restart() {hide('start'); paused = false; playing = true;} - function lose() { show('start'); setVisualScore(); playing = false; } + function lose() { + if (score > highScore) { + highScore = score; + localStorage.setItem('highScore', highScore); + } + show('start'); + setVisualScore(); + playing = false; + } function setVisualScore(n) { vscore = n || score; invalidateScore(); } function setScore(n) { score = n; setVisualScore(n); } From 5f756ac7b85cf5c39149f32ea192cf36c6c9ddc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ca=C3=ADque?= Date: Sun, 11 Oct 2026 20:13:36 -0300 Subject: [PATCH 4/7] feat: adicionar controles e estilos do modo noturno Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- inde.html | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/inde.html b/inde.html index 6762167..d980db3 100644 --- a/inde.html +++ b/inde.html @@ -3,14 +3,36 @@ Javascript Tetris