diff --git a/Games/sand_tetris/assets/1.md b/Games/sand_tetris/assets/1.md new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Games/sand_tetris/assets/1.md @@ -0,0 +1 @@ +1 diff --git a/Games/sand_tetris/assets/screenshot_sand_tetris.png b/Games/sand_tetris/assets/screenshot_sand_tetris.png new file mode 100644 index 0000000000..cd3d4012e4 Binary files /dev/null and b/Games/sand_tetris/assets/screenshot_sand_tetris.png differ 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 @@ + + + +
+ + +