Skip to content

๐ŸŽฎ A modern browser-based Tetris game built with vanilla JavaScript and Go, featuring real-time scoring, WebSocket communication, customizable themes, and persistent leaderboards

Notifications You must be signed in to change notification settings

TanakAiko/make-your-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Tetris Game

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.

Go JavaScript HTML5 CSS3 WebSocket JSON

๐Ÿ“‹ Table of Contents

๐ŸŽฏ Overview

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.

โœจ Features

  • 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

๐Ÿ›  Technologies

Backend

  • Go - Server-side application and WebSocket handler
  • Gorilla WebSocket - WebSocket implementation for real-time communication
  • Go Templates - HTML templating

Frontend

  • Vanilla JavaScript (ES6+) - Game logic and DOM manipulation
  • HTML5 Canvas/DOM - Game rendering
  • CSS3 - Styling and animations
  • WebSocket API - Client-side real-time communication

Data Storage

  • JSON - Score persistence

๐Ÿ“ฆ Installation

Prerequisites

  • Go (version 1.16 or higher)
  • A modern web browser (Chrome, Firefox, Safari, or Edge)

Steps

  1. Clone the repository

    git clone <repository-url>
    cd make-your-game
  2. Install Go dependencies

    go mod download
  3. Run the server

    go run main.go
  4. Open your browser

    Navigate to http://localhost:8080

The game should now be running and ready to play!

๐ŸŽฒ How to Play

  1. Click the Start button to begin a new game
  2. Tetrominoes (game pieces) will fall from the top of the board
  3. Use keyboard controls to move and rotate pieces
  4. Complete horizontal lines to clear them and earn points
  5. The game ends when pieces stack to the top or the timer runs out (180 seconds)
  6. Enter your name to save your score to the leaderboard

Scoring

  • 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!

๐Ÿ“ธ Game Screenshots

Welcome Screen

Tetris Welcome Screen

The welcome screen with color theme options and game controls

Gameplay

Tetris Gameplay

Active gameplay showing the Tetris board, falling pieces, and score tracking

๐ŸŽฎ Game Controls

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

Buttons

  • 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

๐Ÿ“ Project Structure

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

๐Ÿ— Architecture

Game Components

  1. 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
  2. Board Management (board.js)

    • Maintains the game grid state
    • Checks for completed lines
    • Handles line clearing and board updates
  3. Game Panel (gamePanel.js)

    • Manages overall game state
    • Coordinates between different game components
    • Handles game over conditions
  4. Score Manager (scoreManager.js)

    • Tracks current score
    • Communicates with backend via WebSocket
    • Manages leaderboard display
  5. Time Manager (timeManager.js)

    • 180-second countdown timer
    • Pause/resume functionality
    • Game end trigger

Backend Architecture

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

Communication Flow

Client (Browser) โ†โ†’ WebSocket โ†โ†’ Server (Go)
                                    โ†“
                              score.json

๐Ÿค Contributing

Contributions are welcome! If you'd like to improve the game:

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

Ideas for Contributions

  • 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 ๐Ÿ‡ธ๐Ÿ‡ณ

About

๐ŸŽฎ A modern browser-based Tetris game built with vanilla JavaScript and Go, featuring real-time scoring, WebSocket communication, customizable themes, and persistent leaderboards

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published