Skip to content
 
 

Repository files navigation

Chemical - Chain Reaction Multiplayer Game

A real-time, turn-based strategy game inspired by Chain Reaction, built with Next.js, Socket.IO, and TypeScript.

Game Rules

Chemical is played on a grid where players place atoms that can trigger explosive chain reactions:

  • Cell Capacity: Each cell has a critical mass based on its position:

    • Corner cells: 2 atoms
    • Edge cells: 3 atoms
    • Center cells: 4 atoms
  • Gameplay: Players alternate turns placing one atom in empty cells or cells they own

  • Explosions: When a cell reaches its capacity, it explodes, distributing atoms to adjacent cells

  • Cell Conversion: Explosions convert neighboring opponent cells to the current player's color

  • Winning: The last player with atoms on the board wins

Tech Stack

  • Frontend: Next.js 16, React 19, TypeScript, Tailwind CSS, Framer Motion
  • Backend: Next.js API Routes, Socket.IO for real-time multiplayer
  • State Management: Zustand
  • Database: Prisma with SQLite (easily configurable for PostgreSQL)
  • Real-time: Socket.IO for authoritative server architecture

Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

  1. Clone the repository:
git clone <repository-url>
cd chemical
  1. Install dependencies:
npm install
  1. Set up the database:
npm run db:push
npm run db:generate
  1. Seed the database (optional):
npm run db:seed
  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser

Project Structure

chemical/
├── src/
│   ├── app/                    # Next.js App Router
│   │   ├── api/               # API routes
│   │   ├── game/[roomId]/     # Game page
│   │   ├── lobby/             # Lobby page
│   │   └── page.tsx           # Home page
│   ├── components/game/       # Game UI components
│   │   ├── GameBoard.tsx      # Main game board
│   │   ├── Cell.tsx           # Individual cells
│   │   ├── Atom.tsx           # Atom visualization
│   │   ├── PlayerInfo.tsx     # Player information
│   │   ├── TurnIndicator.tsx  # Turn display
│   │   └── WinnerModal.tsx    # Victory screen
│   ├── lib/
│   │   ├── game/              # Core game logic
│   │   ├── socket/            # Socket.IO integration
│   │   └── prisma.ts          # Database client
│   └── types/                 # TypeScript definitions
├── prisma/                    # Database schema and migrations
└── public/                    # Static assets

How to Play

  1. Start: Visit the lobby page and either create a new game or join an existing one
  2. Setup: Enter your name and create a room or enter a room code to join
  3. Play: Click on empty cells or cells you own to place atoms
  4. Strategy: Plan moves to create chain reactions and convert opponent cells
  5. Win: Eliminate all opponent atoms to win the game

Development

Available Scripts

  • npm run dev - Start development server
  • npm run build - Build for production
  • npm run start - Start production server
  • npm run db:studio - Open Prisma Studio
  • npm run db:push - Push schema changes to database
  • npm run db:generate - Generate Prisma client

Database Management

The project uses Prisma with SQLite for development. To switch to PostgreSQL:

  1. Update prisma/schema.prisma:
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
  1. Set your DATABASE_URL environment variable

  2. Run migrations:

npm run db:migrate

Features

Current (MVP)

  • ✅ 2-player multiplayer
  • ✅ 9×6 default board with proper cell capacities
  • ✅ Real-time gameplay with Socket.IO
  • ✅ Chain reaction mechanics
  • ✅ Cell conversion on explosions
  • ✅ Win detection
  • ✅ Responsive UI with animations

Planned

  • 🔄 3-8 player support
  • 🔄 Custom board sizes
  • 🔄 Game replay system
  • 🔄 Player statistics
  • 🔄 Sound effects
  • 🔄 AI opponent

Architecture

The game uses an authoritative server architecture where:

  • Server maintains the canonical game state
  • Server validates all moves and executes game logic
  • Clients receive state updates via WebSocket
  • Prevents cheating and ensures consistency

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - feel free to use this for your projects!

Acknowledgments

  • Inspired by the classic Chain Reaction game
  • Built with modern web technologies for optimal performance
  • Designed for both desktop and mobile play

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages