No description
  • JavaScript 92.5%
  • CSS 5.8%
  • HTML 1.7%
Find a file
Smekhov Aleksandr 9f8c3cbe9b
All checks were successful
Deploy / pre-commit (push) Successful in 1m0s
Deploy / test (push) Successful in 20s
Deploy / deploy (push) Successful in 2s
'Full refactoring.
'Full refactoring.
2026-03-31 21:57:42 +00:00
.forgejo Refactor workflows. Add testing and deployment. 2026-03-31 00:23:46 +03:00
css Add service worker. Refactoring. 2026-04-01 00:45:00 +03:00
favicon Add service worker. Refactoring. 2026-04-01 00:45:00 +03:00
icons finish game logic. 2024-06-11 21:49:56 +03:00
js Add service worker. Refactoring. 2026-04-01 00:45:00 +03:00
tests Add service worker. Refactoring. 2026-04-01 00:45:00 +03:00
.pre-commit-config.yaml Add pre-commit 2026-03-07 16:39:38 +03:00
.prettierrc Add pre-commit 2026-03-07 16:39:38 +03:00
index.html Refactoring. 2026-03-31 23:47:00 +03:00
package.json Add tests. 2026-03-31 00:21:53 +03:00
README.es.md Upgrade README 2026-04-01 00:55:03 +03:00
README.md Upgrade README 2026-04-01 00:55:03 +03:00
README.ru.md Upgrade README 2026-04-01 00:55:03 +03:00
sw.js Add service worker. Refactoring. 2026-04-01 00:45:00 +03:00

Tetris

Read in: English | Русский | Español

A browser-based Tetris game built with pure HTML, CSS, and JavaScript — no frameworks, no dependencies.

Features

  • Classic 20×10 playfield with 7 tetromino types (I, J, L, S, Z, O, T)
  • Wall kick rotation (offsets 0, ±1, ±2)
  • Ghost piece preview showing where the current piece will land
  • Next tetromino preview
  • Hard drop (Space) and soft drop (Arrow Down)
  • Score tracking and line counter
  • Dynamic speed — the game gets faster as you progress
  • Game state persistence via localStorage (resume where you left off)
  • Keyboard and touch controls (swipe, tap, drag)
  • Pause / Resume and Restart at any time
  • Progressive Web App (PWA) with offline support via Service Worker

Tech Stack

Layer Technology
Markup HTML5
Styling CSS3 (custom properties, keyframes)
Logic JavaScript ES2022 (ES modules)
Tests Node.js built-in test runner
Formatting Prettier
CI/CD Forgejo Actions

Getting Started

Prerequisites

  • A modern browser (Chrome, Firefox, Safari, Edge)
  • Node.js v22+ — only required for running tests

Running the Game

No build step required. Open index.html directly in your browser, or serve it with any static file server:

# Example with Python
python -m http.server 8080

# Example with Node.js (npx)
npx serve .

Then navigate to http://localhost:8080.

Running Tests

npm test

Tests use the Node.js built-in test runner — no additional packages needed.

How to Play

  1. Use Arrow Left / Right to move the piece sideways.
  2. Press Arrow Up to rotate.
  3. Press Arrow Down for soft drop.
  4. Press Space for hard drop (instant placement).
  5. Press Escape to pause / resume.
  6. On touch devices: swipe left/right to move, tap to rotate, swipe down to soft drop, swipe up to hard drop.
  7. Fill complete horizontal lines to clear them and score points.

Your progress is saved automatically. Refreshing the page will restore your last session.

Project Structure

├── index.html
├── package.json
├── sw.js                          # Service Worker for offline caching
├── .pre-commit-config.yaml
├── .prettierrc
├── css/
│   ├── index.css                  # CSS entry point (imports)
│   ├── global.css                 # Global styles & CSS variables
│   ├── grid.css                   # Playfield grid layout
│   ├── tetrominoes.css            # Tetromino color definitions
│   ├── info.css                   # Info panel & next-piece preview
│   └── menu.css                   # Navigation/menu styles
├── js/
│   ├── index.js                   # Application entry point
│   ├── board.js                   # Game orchestration & state management
│   ├── tetris.js                  # Core Tetris game logic
│   ├── renderer.js                # DOM rendering & animations
│   ├── game-loop.js               # requestAnimationFrame game loop
│   ├── input-handler.js           # Keyboard & touch input handling
│   ├── consts.js                  # Game constants & tetromino shapes
│   └── utils.js                   # Helper functions
└── tests/
    ├── board.test.js
    ├── consts.test.js
    ├── game-loop.test.js
    ├── input-handler.test.js
    ├── renderer.test.js
    ├── utils.test.js
    └── tetris/                    # Integration tests for game logic
        ├── helpers.js
        ├── init.test.js
        ├── generation.test.js
        ├── movement.test.js
        ├── rotation.test.js
        ├── drop-and-scoring.test.js
        ├── edge-cases.test.js
        ├── game-over.test.js
        ├── persistence.test.js
        └── stress.test.js

CI/CD

Forgejo Actions workflows run on every pull request and push to main:

Workflow Trigger What it does
testing.yml Pull request Runs npm test on Node.js 22
pre-commit.yml Pull request Runs Prettier and file-format checks
deploy.yml Push to main Deploys the game to the server

Contributing

  1. Fork the repository and create a branch from main.
  2. Install pre-commit hooks:
    pip install pre-commit
    pre-commit install
    
  3. Make your changes and ensure tests pass (npm test).
  4. Open a pull request — CI will run automatically.