From bc9da21be12d9667f5fc228e503f9c8c277ac333 Mon Sep 17 00:00:00 2001 From: flo <> Date: Tue, 1 Apr 2025 22:09:47 +0200 Subject: [PATCH] scoring --- public/index.html | 5 ++++- public/script/index.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 58daf5d..6c7682e 100644 --- a/public/index.html +++ b/public/index.html @@ -11,7 +11,10 @@
-

Score: 0

+

+ Score: + 0 +

diff --git a/public/script/index.js b/public/script/index.js index 302a032..07445e0 100644 --- a/public/script/index.js +++ b/public/script/index.js @@ -1,4 +1,5 @@ const board = document.getElementById('tetris-canvas'); +const scoreElement = document.getElementById('score-value'); const boardContext = board.getContext('2d'); @@ -20,6 +21,11 @@ let leftInterval; let keyPress = []; +let score = 0; +let level = 1; +let lines = 0; +let speed = 1000; + const templatePiece = [ [ // ok [3, 0], @@ -279,8 +285,11 @@ function rotate() { } function checkLine() { + let lineFilled = 0; + for (let i = 0; i < 20; i++) { let check = true; + for (let j = 0; j < 10; j++) { if (boardData[j][i][0] == 0 && boardData[j][i][1] == 0 && boardData[j][i][2] == 0) { check = false; @@ -294,8 +303,25 @@ function checkLine() { boardData[k][j] = boardData[k][j - 1]; } } + + lineFilled++; } } + + if (lineFilled == 1) { + score += 40; + } + else if (lineFilled == 2) { + score += 100; + } + else if (lineFilled == 3) { + score += 300; + } + else if (lineFilled == 4) { + score += 1200; + } + + scoreElement.innerText = score; } function moveTo(x, y) { @@ -355,9 +381,7 @@ function fasteDrop() { img.onload = () => { loadTetris(); - drawCurrentPiece(); - - + refresh(); document.addEventListener('keydown', (event) => { if (event.key == 'ArrowUp' && !keyPress.includes('ArrowUp')) {