A modern, browser-based Tetris game built with vanilla JavaScript and Go. Features include real-time scoring, customizable themes, persistent leaderboards, and smooth gameplay mechanics.
๐ Table of Contents
This project is a fully functional Tetris game. It demonstrates modern web development practices, combining a Go backend for server-side logic and WebSocket communication with a vanilla JavaScript frontend for game mechanics and rendering.
- Classic Tetris Gameplay: All standard Tetris mechanics including piece rotation, line clearing, and gravity
- Real-time Scoring System: Track your score with persistent storage
- Global Leaderboard: View top scores from all players with pagination
- Customizable Themes: Choose from 6 different color schemes (Orange, Red, Green, Violet, Blue, Cyan)
- Time-based Challenges: 180-second game sessions with countdown timer
- Game Controls: Pause, resume, and restart functionality
- Responsive Design: Clean, modern UI that works across different screen sizes
- WebSocket Communication: Real-time data synchronization between client and server
- Persistent Data: Scores saved in JSON format for permanent record-keeping
- Go - Server-side application and WebSocket handler
- Gorilla WebSocket - WebSocket implementation for real-time communication
- Go Templates - HTML templating
- Vanilla JavaScript (ES6+) - Game logic and DOM manipulation
- HTML5 Canvas/DOM - Game rendering
- CSS3 - Styling and animations
- WebSocket API - Client-side real-time communication
- JSON - Score persistence
- Go (version 1.16 or higher)
- A modern web browser (Chrome, Firefox, Safari, or Edge)
-
Clone the repository
git clone <repository-url> cd make-your-game
-
Install Go dependencies
go mod download
-
Run the server
go run main.go
-
Open your browser
Navigate to
http://localhost:8080
The game should now be running and ready to play!
- Click the Start button to begin a new game
- Tetrominoes (game pieces) will fall from the top of the board
- Use keyboard controls to move and rotate pieces
- Complete horizontal lines to clear them and earn points
- The game ends when pieces stack to the top or the timer runs out (180 seconds)
- Enter your name to save your score to the leaderboard
- Clear lines to earn points
- The more lines you clear at once, the higher your score
- Try to beat your personal best and climb the leaderboard!
| Key | Action |
|---|---|
| โ (Left Arrow) | Move piece left |
| โ (Right Arrow) | Move piece right |
| โ (Down Arrow) | Soft drop (move piece down faster) |
| Space | Hard drop (instantly drop piece) |
| โ (Up Arrow) or W | Rotate piece clockwise |
| P | Pause game |
| R | Restart game |
- Start: Begin a new game
- Pause: Pause the current game
- Resume: Continue a paused game
- Restart: Start a fresh game (resets score and timer)
- View Scores: Check the global leaderboard
make-your-game/
โโโ main.go # Go server and WebSocket handler
โโโ go.mod # Go module dependencies
โโโ go.sum # Go module checksums
โโโ index.html # Main HTML file
โโโ score.json # Persistent score storage
โโโ README.md # Project documentation
โโโ script/
โ โโโ init.sh # Initialization script
โ โโโ push.sh # Deployment script
โโโ statics/
โโโ style.css # Main stylesheet
โโโ images/ # Game assets
โ โโโ background.jpg
โ โโโ down.png
โ โโโ left.webp
โ โโโ right.svg
โ โโโ up.png
โโโ js/ # JavaScript modules
โโโ main.js # Main game loop and event handlers
โโโ Tetrominos.js # Tetromino class and shapes
โโโ board.js # Game board logic
โโโ gamePanel.js # Game panel management
โโโ scoreManager.js # Score tracking and persistence
โโโ timeManager.js # Timer functionality
โโโ learn.js # Tutorial/learning features
-
Tetromino System (
Tetrominos.js)- Defines all 7 standard Tetris pieces (I, O, T, S, Z, J, L)
- Handles piece rotation, movement, and collision detection
- Manages piece rendering and deletion
-
Board Management (
board.js)- Maintains the game grid state
- Checks for completed lines
- Handles line clearing and board updates
-
Game Panel (
gamePanel.js)- Manages overall game state
- Coordinates between different game components
- Handles game over conditions
-
Score Manager (
scoreManager.js)- Tracks current score
- Communicates with backend via WebSocket
- Manages leaderboard display
-
Time Manager (
timeManager.js)- 180-second countdown timer
- Pause/resume functionality
- Game end trigger
The Go server (main.go) provides:
- HTTP Server: Serves static files and HTML templates
- WebSocket Handler: Real-time bidirectional communication
- Score Persistence: Reads/writes to
score.json - Leaderboard API: Retrieves and ranks player scores
Client (Browser) โโ WebSocket โโ Server (Go)
โ
score.json
Contributions are welcome! If you'd like to improve the game:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Add difficulty levels (faster gravity at higher levels)
- Implement ghost piece preview
- Add sound effects and background music
- Create mobile touch controls
- Add multiplayer functionality
- Implement next piece preview
- Add special power-ups
โญ Star this repository if you found it helpful! โญ
Made with โค๏ธ from ๐ธ๐ณ

