A classic Tetris game implemented using HTML, CSS, JavaScript ... and little AI-trainer-mentor
Scan the QR code to play instantly on your phone:
๐ก Tip: Add the game to your home screen for a native app experience! The game works offline as a PWA.
This implementation of the classic Tetris game includes all the main elements of the originalโplus several modern enhancements:
- Seven standard tetrominos (I, J, L, O, S, T, Z)
- Increasing difficulty with each level
- Scoring system with soft/hard drop bonuses
- Display of the next piece
- Ghost piece preview - See where your piece will land with a semi-transparent shadow
- Option to enable/disable the grid overlay
- Procedural 8-bit sound system using Web Audio API - Game sounds with no external dependencies
- Adaptive learning engine that analyzes player mistakes
- Optional touch controls for mobile and tablet devices
- Persistent high-score and grid preference storage
- Classic Tetris with 7 standard tetrominos (I, J, L, O, S, T, Z)
- Smooth canvas-based rendering at 60 FPS
- Ghost piece showing where the active piece will land
- Scoring system with soft/hard drop bonuses
- Level progression with increasing speed (every 10 lines)
- Next piece preview
- Pause/resume functionality
- Toggleable grid overlay
- Procedural 8-bit sound effects via Web Audio API
- Unique sounds for move, rotate, drop, line clear, Tetris, level up, game over
- Volume control and mute toggle
- Zero external audio files โ all sounds generated programmatically
- Adaptive learning engine that analyzes player mistakes
- AI Insight panel with real-time strategy feedback
- AI vs AI Mode โ watch two AI players compete
- Dual AI system: aggressive (AI 1) vs defensive (AI 2)
- Player intervention โ take control from AI at any time
- 8 purchasable visual themes (Classic, Ocean, Inferno, Matrix, Neon, Pastel, Gold, Rainbow)
- TetriCoins shop for spending virtual currency
- Multiple block rendering styles (flat, gradient, glossy)
- Persistent theme preferences
- TetriCoins (TC) virtual currency
- Earn TC by clearing lines (10-500 TC based on lines cleared)
- Daily bonus (+100 TC)
- Betting system for AI vs AI matches (4 bet types with different odds)
- Tournament mode with jackpot system
- Record game sessions as compact input logs
- Share replays via URL links โ recipients can watch your game
- Save up to 10 replays locally
- Deterministic playback using seeded random generation
- Web Share API integration for mobile sharing
- Achievement system with TC rewards
- Local leaderboard (Top 10)
- Social sharing (score, replays)
- Achievement notifications with animations
- Installable on mobile devices (Add to Home Screen)
- Full offline support via Service Worker
- Responsive design for mobile, tablet, and desktop
- Touch controls with swipe gestures
- Haptic feedback (vibration API)
- 4 languages: English, ะ ัััะบะธะน, ไธญๆ, ุงูุนุฑุจูุฉ
- Language selection screen on first visit
- Full UI translation including achievements, shop, and replays
| Key | Action |
|---|---|
| โ โ | Move piece left/right |
| โ | Rotate piece |
| โ | Soft drop (faster descent) |
| Space | Hard drop (instant placement) |
| P | Pause / Resume |
| G | Toggle grid overlay |
| M | Mute / Unmute sound |
| T | Take control (AI vs AI mode) |
- Swipe left/right โ Move piece
- Tap โ Rotate
- Swipe down โ Hard drop
- On-screen buttons for all controls
- AI vs AI Mode button โ Start AI competition
- T key / Take Control button โ Intervene in AI gameplay
- Exit AI Mode button โ Return to normal play
- 1 line: 40 ร level
- 2 lines: 100 ร level
- 3 lines: 300 ร level
- 4 lines: 1200 ร level
- Soft drop: +1 point per cell
- Hard drop: +2 points per cell
| Technology | Usage |
|---|---|
| HTML5 Canvas | Game rendering |
| CSS3 | Responsive UI, animations, themes |
| Vanilla JavaScript | Game logic, ES modules |
| Web Audio API | Procedural sound generation |
| Service Worker | Offline PWA support |
| LocalStorage | Persistent data (scores, themes, replays) |
| Web Share API | Native sharing on mobile |
| Vibration API | Haptic feedback |
Zero external dependencies โ everything is built with native web APIs.
- Clone the repository or download the project files
- Open
index.htmlin any modern web browser - Click the "Start Game" button to begin playing
โโโ index.html # Main HTML file
โโโ tetris.js # Main game entry point (ES module)
โโโ style.css # Core styles
โโโ sw.js # Service Worker
โโโ manifest.json # PWA manifest
โโโ css/
โ โโโ betting-panel.css # Betting UI styles
โ โโโ language.css # Language selection styles
โ โโโ share.css # Share UI styles
โ โโโ team-tournament.css # Tournament styles
โโโ js/
โ โโโ achievements.js # Achievement system
โ โโโ betting.js # Betting system
โ โโโ currency.js # TetriCoins currency
โ โโโ i18n.js # Internationalization
โ โโโ language-selector.js # Language UI
โ โโโ pwa.js # PWA registration
โ โโโ team-tournament.js # Tournament logic
โ โโโ team-tournament-ui.js # Tournament UI
โ โโโ modules/
โ โโโ core/ # Core game logic
โ โโโ rendering/ # Canvas rendering
โ โโโ input/ # Input handling
โ โโโ ai/ # AI systems
โ โโโ audio/ # Sound engine
โ โโโ game/ # Game systems (scoring, UI, themes, replays)
โโโ icons/ # PWA icons
โโโ tetris-textbook*.md # Game tutorials
โโโ tetris-strategist*.md # Strategy guides
โโโ README*.md # Documentation (EN, RU, CH)
New Feature! Watch two AI players compete against each other in this exciting game mode that demonstrates advanced strategic thinking and adaptive learning.
- AI Competition: Two independent AI engines play against each other, each learning and adapting to the board state
- Real-time Analysis: Each AI shows its thinking process and strategic planning in real-time
- Player Learning: Observe sophisticated AI decision-making to improve your own Tetris skills
- Player Intervention: Take control at any time using the 'T' key or "Take Control" button
- Dual AI System: Two separate AI players with independent learning algorithms
- Strategic Analysis: Each AI analyzes the board and explains its reasoning
- Visual Feedback: Color-coded UI showing which AI is active (Red AI 1 vs Blue AI 2)
- Educational Value: Perfect for learning advanced Tetris strategies by observing AI gameplay
- Seamless Integration: Switch between normal gameplay and AI vs AI mode instantly
- AI vs AI Mode Button: Start AI vs AI gameplay
- T Key: Take control from the current AI player
- Take Control Button: Alternative way to intervene in AI gameplay
- Exit AI Mode Button: Return to normal gameplay
This mode is perfect for players who want to:
- Learn advanced Tetris strategies by watching AI gameplay
- Understand how different AI approaches handle various board situations
- Practice taking over from AI at critical moments
- Experience the educational value of AI vs AI competition
The built-in trainer observes each of your placements and increases the frequency of pieces that caused troubleโsuch as creating holes or raising tall columnsโwhile reducing shapes that helped you recover. It never changes the fall speed, keeping gameplay fair. During the round the AI Insight panel calls out what it noticed most recently, and after a top-out it explains exactly how it capitalized on your mistakes so you can adjust your strategy next time.
Create a classic Tetris game implementation using HTML, CSS, and JavaScript with the following specifications:
-
Game Structure:
- Create an HTML file with a main game canvas (300x600px) for the Tetris board
- Add a secondary canvas (100x100px) to display the next piece
- Set up a score display area showing score, level, and lines cleared
- Include Start/Restart button and Grid Toggle button
- Add a controls guide section
-
Game Mechanics:
- Implement a 10x20 grid for the game board
- Create the 7 standard tetromino shapes (I, J, L, O, S, T, Z) with distinct colors
- Set up piece movement (left, right, down), rotation, and collision detection
- Implement soft drop (faster descent) and hard drop (instant placement)
- Add line clearing with appropriate scoring
- Implement level progression (every 10 lines) with increasing speed
- Include game over detection when pieces stack to the top
- Add pause functionality
-
Visual Elements:
- Style the game with a dark theme (black background for game area)
- Add a shine effect to each tetromino block
- Implement optional grid display that can be toggled on/off
- Create a start screen, pause screen, and game over screen with appropriate messages
- Ensure the next piece preview shows the upcoming tetromino centered in its canvas
-
Controls:
- Arrow keys for movement (left, right, down) and rotation (up)
- Space bar for hard drop
- P key for pause/resume
- G key for toggling grid visibility
-
Scoring System:
- 40 ร level points for 1 line
- 100 ร level points for 2 lines
- 300 ร level points for 3 lines
- 1200 ร level points for 4 lines
- 1 bonus point for each cell in soft drop
- 2 bonus points for each cell in hard drop
Implement the game using vanilla JavaScript with the Canvas API for rendering, ensuring smooth gameplay with appropriate animation timing. The implementation should be responsive and work in modern browsers without external libraries.
We welcome contributions! See CONTRIBUTING.md for guidelines.
- Fork the repository
- Open
index.htmlin a browser (no build step needed!) - Make your changes
- Submit a Pull Request
- ๐ Add translations for new languages (Japanese, Korean, Spanish, etc.)
- ๐จ Create new visual themes
- ๐ Add new sound patterns
- ๐ Improve documentation
- ๐ Report and fix bugs
See the ROADMAP.md for more ideas.
[GitHub Copilot] + [NinelGPT]
This project is licensed under FREE
