Skip to content

abhinavramanan/Tetris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Tetris Game

A classic Tetris game implementation built with vanilla HTML, CSS, and JavaScript. Experience the timeless puzzle game with modern web technologies, featuring smooth animations, visual effects, and responsive design.

Tetris Game HTML5 CSS3 JavaScript

๐Ÿ“ธ Screenshots

Dark Theme Gameplay Light Theme Gameplay Initial Rules Screen
Dark Theme Light Theme Rules Screen

๐Ÿ“– Table of Contents

โœจ Features

  • ๐ŸŽฏ Classic Tetris Gameplay: All 7 traditional Tetris pieces (I, O, T, S, Z, J, L)
  • ๐Ÿ“Š Progressive Difficulty: 20 levels with increasing speed
  • ๐ŸŒŸ Visual Effects: Line clear animations (Single, Double, Triple, Tetris!)
  • ๐Ÿ‘ป Ghost Piece: Preview where your piece will land
  • โธ๏ธ Pause/Resume: Press ESC to pause anytime
  • ๐ŸŽจ Theme Toggle: Switch between light and dark themes
  • ๐Ÿ“ฑ Mobile Responsive: Optimized for desktop and mobile devices
  • ๐ŸŽต Classic Scoring: Traditional Tetris scoring system
  • โฑ๏ธ Time Tracking: Monitor your play time
  • ๐Ÿ”„ Restart Functionality: Easy game restart after game over

๐Ÿš€ Quick Start

๐ŸŽฎ Play Online

Simply open index.html or https://abhinavramanan.github.io/Tetris/ in your web browser to start playing immediately!

Option 1: Direct File Opening

  1. Download or clone this repository
  2. Open index.html in your web browser
  3. Click "Start Game" and enjoy!

Option 2: Online (Recommended)

visit: https://abhinavramanan.github.io/Tetris/

๐ŸŽฎ How to Play

  1. Start: Click the "Start Game" button or press "Start Game" in the rules modal
  2. Objective: Fill complete horizontal lines to clear them and score points
  3. Strategy: Arrange falling Tetris pieces to create solid lines without gaps
  4. Progression: Clear lines to advance levels and increase game speed
  5. End Game: Game ends when pieces reach the top of the playing field

Scoring System

  • Single Line: Base points ร— level multiplier
  • Double Lines: Higher bonus points
  • Triple Lines: Even higher bonus points
  • Tetris (4 lines): Maximum bonus points with special animation
  • Piece Placement: Small bonus for each piece placed

๐ŸŽฏ Game Controls

Key Action
โฌ…๏ธ Left Arrow Move piece left
โžก๏ธ Right Arrow Move piece right
โฌ‡๏ธ Down Arrow Move piece down (soft drop)
โฌ†๏ธ Up Arrow Rotate piece clockwise
ESC Pause/Resume game

Additional Controls

  • Theme Button: Toggle between light and dark themes (top-right corner)
  • Start/Restart Button: Begin new game or restart after game over
  • Resume Button: Continue game after pause

๐ŸŒŸ Game Features

Visual Effects

  • Line Clear Animations: Different effects for Single, Double, Triple, and Tetris clears
  • Screen Flash: Brief flash effect when clearing lines
  • Ghost Piece: Semi-transparent preview showing landing position
  • Smooth Animations: Fluid piece movement and transitions

Game Mechanics

  • Level Progression: 20 levels with increasing difficulty
  • Speed Increase: Game speed increases with each level
  • Next Piece Preview: See what piece is coming next
  • Classic Piece Colors:
    • T-piece (Cyan) - Type 0
    • I-piece (Red) - Type 1
    • L-piece (Orange) - Type 2
    • J-piece (Purple) - Type 3
    • S-piece (Green) - Type 4
    • Z-piece (Yellow) - Type 5
    • O-piece (Blue) - Type 6

Modern Enhancements

  • Responsive Design: Works on desktop, tablet, and mobile
  • Theme Support: Light and dark mode toggle
  • Pause Functionality: Pause overlay with resume option
  • Level Up Modals: Celebration when advancing levels
  • Game Over Handling: Clear indication and restart option

๐Ÿ”ง Technical Details

Technologies Used

  • HTML5: Semantic markup and game structure
  • CSS3: Styling, animations, and responsive design
  • Vanilla JavaScript: Game logic and DOM manipulation

Browser APIs Used

  • DOM Manipulation: Dynamic element creation and modification
  • Event Listeners: Keyboard and mouse input handling
  • CSS Animations: Smooth visual effects and transitions
  • Local Storage: (Future enhancement for high scores)

Code Architecture

  • Modular Design: Game logic separated into logical functions
  • Object-Oriented: Main game object with organized methods
  • Event-Driven: Responsive to user input and game events
  • Cross-Browser: Compatible with modern browsers

๐Ÿ“ File Structure

Tetris/
โ”œโ”€โ”€ index.html          # Main HTML structure and game layout
โ”œโ”€โ”€ script.js           # Complete game logic and functionality
โ”œโ”€โ”€ styles.css          # Styling, animations, and responsive design
โ””โ”€โ”€ README.md          # This documentation file

File Descriptions

index.html

  • Game canvas and playing field
  • Info panel with score, level, lines, time
  • Next piece preview area
  • Pause, level-up, and rules modals
  • Control buttons and UI elements

script.js

  • Core Tetris game engine
  • Piece movement and rotation logic
  • Line clearing and scoring system
  • Level progression and speed control
  • Visual effects and animations
  • Input handling and game state management

styles.css

  • Classic Tetris visual styling
  • Responsive design for all devices
  • CSS animations and transitions
  • Theme system (light/dark modes)
  • Mobile-optimized layouts

๐ŸŒ Browser Compatibility

Supported Browsers

  • โœ… Chrome 60+ (Recommended)
  • โœ… Firefox 55+
  • โœ… Safari 11+
  • โœ… Edge 79+
  • โœ… Opera 47+

Mobile Support

  • โœ… iOS Safari 11+
  • โœ… Chrome Mobile 60+
  • โœ… Firefox Mobile 55+
  • โœ… Samsung Internet 7+

Requirements

  • JavaScript: Must be enabled
  • CSS3: For animations and modern styling
  • HTML5: For semantic structure
  • No plugins: Runs entirely in the browser

๐Ÿ’ป Development

Local Development Setup

# Clone and navigate
git clone https://github.com/abhinavramanan/Tetris.git
cd Tetris

# Start development server
python3 -m http.server 8000
# or
npx http-server

# Open http://localhost:8000 in your browser

Code Style

  • ES5/ES6 Compatible: Works in older and modern browsers
  • Vanilla JavaScript: No external dependencies
  • Modular Functions: Easy to understand and modify
  • Comments: Well-documented for easy maintenance

Customization Options

  • Colors: Modify piece colors in CSS (.type0 - .type6)
  • Speed: Adjust speed values in script.js
  • Board Size: Change canvasHeight and canvasWidth
  • Scoring: Modify scoring multipliers in initLevelScores()

๐Ÿค Contributing

Contributions are welcome! Here are some ways you can help improve the game:

Potential Enhancements

  • ๐ŸŽต Sound Effects: Add audio for line clears, piece drops, and game events
  • ๐Ÿ† High Scores: Local storage for best scores
  • ๐ŸŽฎ Touch Controls: Swipe gestures for mobile devices
  • ๐ŸŽจ More Themes: Additional color schemes and visual styles
  • ๐Ÿ“Š Statistics: Detailed gameplay statistics tracking
  • ๐ŸŒ Multiplayer: Real-time multiplayer functionality
  • ๐ŸŽฏ Game Modes: Sprint, Marathon, and Challenge modes

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Guidelines

  • Maintain compatibility with supported browsers
  • Follow existing code style and patterns
  • Add comments for new functionality
  • Test on multiple devices and browsers
  • Update documentation for new features

๐Ÿ“„ License

This project is open source and available under the MIT License.


๐ŸŽ‰ Have Fun!

Enjoy playing this classic Tetris game! Whether you're a casual player or a Tetris master, this implementation offers the authentic experience you love with modern web enhancements.

Happy Gaming! ๐ŸŽฎ


Built with โค๏ธ using vanilla web technologies

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •