From fffcaf42579987a023974491098efaaeadb55c98 Mon Sep 17 00:00:00 2001 From: Markcosay <76439807+Markcosay@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:47:10 +0530 Subject: [PATCH 1/7] Create readme.md Adding readme to sand tetris game --- Games/sand_tetris/readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Games/sand_tetris/readme.md diff --git a/Games/sand_tetris/readme.md b/Games/sand_tetris/readme.md new file mode 100644 index 0000000000..8178c76d62 --- /dev/null +++ b/Games/sand_tetris/readme.md @@ -0,0 +1 @@ +readme From 4cdccbf7daf103b72d407a576f2f4036bf9bc5ef Mon Sep 17 00:00:00 2001 From: Markcosay <76439807+Markcosay@users.noreply.github.com> Date: Wed, 24 Jul 2024 00:47:52 +0530 Subject: [PATCH 2/7] Add files via upload --- Games/sand_tetris/handleinput.js | 45 +++ Games/sand_tetris/index.html | 129 ++++++++ Games/sand_tetris/logo.png | Bin 0 -> 7430 bytes Games/sand_tetris/piece.js | 258 ++++++++++++++++ Games/sand_tetris/playfield.js | 125 ++++++++ Games/sand_tetris/script.js | 508 +++++++++++++++++++++++++++++++ Games/sand_tetris/style.css | 10 + 7 files changed, 1075 insertions(+) create mode 100644 Games/sand_tetris/handleinput.js create mode 100644 Games/sand_tetris/index.html create mode 100644 Games/sand_tetris/logo.png create mode 100644 Games/sand_tetris/piece.js create mode 100644 Games/sand_tetris/playfield.js create mode 100644 Games/sand_tetris/script.js create mode 100644 Games/sand_tetris/style.css diff --git a/Games/sand_tetris/handleinput.js b/Games/sand_tetris/handleinput.js new file mode 100644 index 0000000000..a70a290075 --- /dev/null +++ b/Games/sand_tetris/handleinput.js @@ -0,0 +1,45 @@ +// Left Arrow Key: 37 +// Up Arrow Key: 38 +// Right Arrow Key: 39 +// Down Arrow Key: 40 + +document.addEventListener('keydown', event => { + if ([32, 37, 38, 39, 40].includes(event.keyCode)) { + event.preventDefault(); + } + switch (event.keyCode) { + + // Down arrow + case 40: + fallingPiece.moveDown(); + if (!playfield.isValid(fallingPiece)) + fallingPiece.moveUp() + else + fallingPiece.resetBuffer() + break; + // Top arrow + case 38: + fallingPiece.rotateCW(); + + // if not valid, rotate back + if (!playfield.isValid(fallingPiece)) + fallingPiece.rotateCCW(); + + break; + + // Left arrow + case 37: + fallingPiece.moveLeft(); + if (!playfield.isValid(fallingPiece)) + fallingPiece.moveRight() + break; + + // Right Arrow + case 39: + fallingPiece.moveRight(); + if (!playfield.isValid(fallingPiece)) + fallingPiece.moveLeft() + break; + } + +}); \ No newline at end of file diff --git a/Games/sand_tetris/index.html b/Games/sand_tetris/index.html new file mode 100644 index 0000000000..2327c3f4d4 --- /dev/null +++ b/Games/sand_tetris/index.html @@ -0,0 +1,129 @@ + + + +
+ + +