Skip to content

CreativeAcer/de-rat--game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐀 De Rat - Social Deduction Party Game CodeFactor

A Matrix-themed social deduction game where players try to identify the hidden traitor among them. One player is secretly "De Rat" and must avoid detection while sabotaging the group.

Home Screen

🎮 How to Play

  1. Setup: Host adds all players and secretly assigns one as "De Rat"
  2. Rounds: Each round, players answer questions on their phones
  3. Scoring: Correct answers earn points, wrong answers don't
  4. Voting: Everyone votes on who they think is De Rat
  5. Elimination: The lowest scorer (who isn't De Rat) gets eliminated
  6. Win Conditions:
    • Players win: If everyone correctly identifies De Rat
    • Rat wins: If only the Rat and one other player remain

🚀 Quick Start

Option 1: Docker Compose (Recommended)

# Clone or extract the game files
cd de-rat-game

# Find your local IP first:
# Linux/Mac: hostname -I | awk '{print $1}'
# Windows: ipconfig (look for IPv4 Address under your WiFi/Ethernet adapter)

# Start with your IP (replace with your actual IP!)
HOST_IP=192.168.1.100 docker-compose up -d

# Or on Windows PowerShell:
$env:HOST_IP="192.168.1.100"; docker-compose up -d

# View logs
docker-compose logs -f

# Stop the game
docker-compose down

Option 2: Podman (Open Source Alternative)

# Clone or extract the game files
cd de-rat-game

# Find your IP: hostname -I | awk '{print $1}'

# Start with podman-compose
HOST_IP=192.168.1.100 podman-compose up -d

# OR use podman directly:
podman build -t de-rat-game .
podman run -d --name de-rat -p 3000:3000 -e HOST_IP=192.168.1.100 -v de-rat-data:/app/data de-rat-game

# View logs
podman logs -f de-rat

# Stop
podman stop de-rat && podman rm de-rat

Option 3: Standalone HTML (No Server Required)

Just open docs/standalone.html in any browser. Game state is saved locally in your browser.

🌐 Accessing the Game

Once running, open your browser to:

To find your IP address:

  • Linux/Mac: hostname -I or ip addr
  • Windows: ipconfig

Multi-Device Setup

  1. Host opens http://localhost:3000 and enters Admin mode
  2. Host creates players and shares their personal links
  3. Each player opens their link on their phone
  4. Players answer questions, host manages the game

📁 Project Structure

de-rat-game/
├── docker-compose.yml  # Docker/Podman compose file
├── Dockerfile          # Container build instructions
├── backend/
│   ├── server.js       # Express + Socket.io server
│   └── package.json    # Node.js dependencies
├── frontend/
│   └── index.html      # Main game interface
└── docs/
    └── standalone.html # Standalone version (no server)

🔧 Configuration

Environment Variables

Variable Default Description
PORT 3000 Server port
NODE_ENV production Node environment

Changing the Port

# Docker Compose - edit docker-compose.yml or:
PORT=8080 docker-compose up -d

# Direct Docker/Podman:
docker run -d -p 8080:3000 de-rat-game

💾 Data Persistence

Game state is stored in a Docker volume (game-data). To backup:

# Docker
docker cp de-rat-game:/app/data/gamestate.json ./backup.json

# Podman
podman cp de-rat:/app/data/gamestate.json ./backup.json

To reset the game data:

docker-compose down -v  # Removes the volume
docker-compose up -d    # Fresh start

🛠️ Development

Running Locally (Without Docker)

cd backend
npm install
npm start

Building the Image

# Docker
docker build -t de-rat-game .

# Podman
podman build -t de-rat-game .

Arcihtecture

┌───────────────────────────────────────────────────────────────────────┐
│                         YOUR COMPUTER                                 │
│                                                                       │
│  ┌──────────────────────────────────────────────────────────────────┐ │
│  │                    DOCKER/PODMAN CONTAINER                       │ │
│  │                                                                  │ │
│  │   ┌──────────────────────────────────────────────────────────┐   │ │
│  │   │              Node.js Server (Express)                    │   │ │
│  │   │                    Port 3000                             │   │ │
│  │   │                                                          │   │ │
│  │   │   /api/state     ←→  Game State (read/write)             │   │ │
│  │   │   /api/hostip    →   Returns host IP                     │   │ │
│  │   │   /api/player/:id →  Player-specific data                │   │ │
│  │   │   Socket.io      ←→  Real-time updates                   │   │ │
│  │   │                                                          │   │ │
│  │   │   Serves: /public/index.html (the game UI)               │   │ │
│  │   └──────────────────────────────────────────────────────────┘   │ │
│  │                            │                                     │ │
│  │                            │ reads/writes                        │ │
│  │                            ▼                                     │ │
│  │                    /app/data/gamestate.json                      │ │
│  │                            │                                     │ │
│  └────────────────────────────│─────────────────────────────────────┘ │
│                               │                                       │
│                               │ MOUNTED VOLUME                        │
│                               ▼                                       │
│  ┌──────────────────────────────────────────────────────────────────┐ │
│  │                 DOCKER VOLUME: game-data                         │ │
│  │                                                                  │ │
│  │   Location: /var/lib/docker/volumes/de-rat-game_game-data/       │ │
│  │             (or similar for Podman)                              │ │
│  │                                                                  │ │
│  │   Contains: gamestate.json                                       │ │
│  │                                                                  │ │
│  │   ⚠️ THIS PERSISTS even when container is rebuilt!               │ │
│  └──────────────────────────────────────────────────────────────────┘ │
│                                                                       │
└───────────────────────────────────────────────────────────────────────┘

        │
        │ Port 3000 exposed
        ▼

┌───────────────────────┐     ┌─────────────────────────┐
│   HOST BROWSER        │     │   PLAYER PHONES         │
│   (Admin)             │     │                         │
│                       │     │                         │
│ http://localhost:3000 │     │ http://192.168.x.x:3000 │
│                       │     │   ?player=p12345        │
└───────────────────────┘     └─────────────────────────┘

🎨 Features

  • Matrix-themed UI with green terminal aesthetics
  • Real-time sync across all connected devices
  • Dramatic elimination with fingerprint scanning animation
  • Win detection with game over screens
  • Score tracking across multiple rounds
  • Question templates for quick setup
  • Import/Export game state for backup
  • Undo elimination in case of mistakes

📱 Browser Support

Works on all modern browsers:

  • Chrome, Firefox, Safari, Edge
  • Mobile browsers (iOS Safari, Chrome for Android)

🐛 Troubleshooting

Container won't start

# Check logs
docker-compose logs

# Rebuild
docker-compose build --no-cache
docker-compose up -d

Can't connect from other devices

  • Ensure firewall allows port 3000
  • Use your local IP, not localhost
  • Check devices are on the same network

Podman permission issues

# Run with user namespace
podman run --userns=keep-id -p 3000:3000 de-rat-game

Fully reset data

Option 1: Remove volume explicitly

docker-compose down -v

Option 2: Remove volume manually

docker volume rm de-rat-game_game-data

For Podman:

podman volume rm de-rat-game_game-data

📊 Data Flow Summary

┌──────────────┐    HTTP/WebSocket    ┌──────────────┐    File I/O    ┌─────────────────┐
│   Browser    │ ◄──────────────────► │   Server     │ ◄────────────► │ gamestate.json  │
│   (UI)       │                      │  (Node.js)   │                │ (Docker Volume) │
└──────────────┘                      └──────────────┘                └─────────────────┘
  1. Browser sends action (add player, submit answer, etc.)
  2. Server updates in-memory state
  3. Server writes to gamestate.json
  4. Server broadcasts update via Socket.io
  5. All connected browsers receive update

📄 Standalone Version (Different!)

The standalone HTML file (standalone.html) uses browser localStorage instead:

┌───────────────────────────────────────┐
│           BROWSER                     │
│                                       │
│   ┌──────────────────────────────┐    │
│   │      standalone.html         │    │
│   │                              │    │
│   │   JavaScript Game Logic      │    │
│   │          │                   │    │
│   │          ▼                   │    │
│   │   localStorage.setItem(      │    │
│   │     'deRatV8',               │    │
│   │     JSON.stringify(state)    │    │
│   │   )                          │    │
│   └──────────────────────────────┘    │
│                                       │
│   Browser Storage (persists locally)  │
└───────────────────────────────────────┘
  • No server needed
  • Data stays in YOUR browser only
  • Other devices can't connect
  • Clearing browser data = lose game

📄 License

MIT License - Feel free to modify and share!


Have fun finding De Rat! 🐀

About

Social deduction game

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors