Skip to content

Repository files navigation

♠️ Durak Elite Card Game

A full-stack, real-time multiplayer implementation of the classic Eastern European card game, featuring custom stakes/economy, persistent leaderboards, single-player bot matchmaking, and a predictive AI consultant.

TypeScript Next.js Socket.io Tailwind CSS MongoDB Redis


📖 Overview

Durak Elite is a highly engaging card game dashboard designed with Next.js, Express, Socket.io, and Tailwind CSS. The app features state-of-the-art socket room orchestration that supports both:

  1. Artificial Mode (Single Player) — Practice against local bots running aggressive card management algorithms.
  2. Network Mode (Multiplayer) — Spin up real-time game lobbies, share room invite links, and compete with friends online.

The platform includes a persistent ledger system integrated with MongoDB Atlas that rewards winners and charges the Durak (the loser left with cards) based on custom game stakes.


💡 Making Life Easier: Solved Daily Problems

While games are designed for fun, this application specifically solves several daily friction points for players and remote friends:

1. Fast Cognitive Reset (Relieving Stress & Mental Fatigue)

  • The Daily Problem: Long hours of coding, studying, or office work lead to brain fog and decreased productivity. Traditional games are either too long (like Monopoly) or require too much setup.
  • How This App Solves It: Durak is a game of quick, high-stakes tactical reasoning. A single match takes 3 to 7 minutes. Playing a quick round against a bot acts as a perfect cognitive micro-break, resetting your focus and relieving stress without wasting half your day.

2. Social Isolation & Remote Bonding (No-Friction Lobbies)

  • The Daily Problem: Keeping in touch with remote friends or coworkers is hard. Finding a lightweight activity to do together during a lunch break or over a call usually involves signing up for complex gaming platforms.
  • How This App Solves It: Host a Network Mode lobby in one click. The application generates a direct invite link (http://localhost:3000?room=ROOM_ID) that copy-pastes instantly. Friends can join the room on any browser (mobile or desktop) in seconds without signing up.

3. Rules Disputes & Rule Enforcement

  • The Daily Problem: Playing physical Durak often leads to friendly arguments. "Is Transfer (Perevodnoy) allowed?", "Can you attack with that card?", "Who has to defend first?"
  • How This App Solves It: The server-side Game Engine acts as an automated referee. It enforces absolute game state synchronization, standard rules, and transfer (Perevodnoy) logic automatically. Illegal moves are rejected instantly by the UI, keeping the game smooth and friendly.

4. Learning the Game (Consultant Mode / Predictive AI)

  • The Daily Problem: Card game strategies can be intimidating for beginners. Learning when to save your trump cards, when to take a hit, and which card to attack with takes years of practice.
  • How This App Solves It: Toggling Consultant Mode turns on a local predictive AI assistant. When it's your turn, the assistant calculates the game state in real-time and highlights the recommended card to play (or advises you to Pass/Take). It lowers the entry barrier for new players and makes mastering the game easy.

5. Cheat-Proof Fair Play (Fog of War)

  • The Daily Problem: Peer-to-peer web games are notorious for client-side modifications where players inspect network requests or state variables to see their opponents' cards.
  • How This App Solves It: The backend state dispatcher uses a strict Fog of War logic. Hand data is sanitized server-side. Other players' cards are sent as { hidden: true } and only unmasked for the active owner. Cheating via browser developer tools is mathematically impossible.

⏱️ Before vs. After: Playing Card Games

Activity Traditional Card Game (Before) Durak Elite (After)
Setup & Cleanup Carry a physical deck, find a flat surface, shuffle, deal. 1 click / Instant deal from the browser.
Finding Players Need a physical gathering of 2–6 people. Play instantly against Bot AI or spin up an online lobby.
Keeping Score Paper scoring or memory (leading to arguments). Synced MongoDB leaderboard with game history and currency balances.
Learning Strategy Trial-and-error, losing matches out of confusion. Predictive AI Advisor coaches you on the fly.

✨ Key Features

  • Multiplayer Room Orchestration: Robust WebSockets rooms handling real-time card playing, turn progression, and lobby synchronization.
  • Rematch System: One-click rematch trigger that resets game instances and redistributes hands without kicking players back to the lobby.
  • Local Bot AI: Single-player bots with customizable difficulty levels that play cards aggressively (cheapest non-trumps first).
  • Flexible Rulesets: Support for deck sizes (24, 36, or 52 cards) and standard or Transfer (Perevodnoy) game rules.
  • Stakes-Based Economy: Contract stakes of $100, $1K, or $10K with balances synced to MongoDB Atlas.
  • Custom Reaction Tray: Send real-time emojis directly onto the table felt.
  • Responsive Styling: Framer Motion transitions and premium deep-felt textures configured for mobile, tablet, and desktop viewports.

🏗️ Architecture

┌────────────────────────────────────────────────────────────────────────┐
│                        Next.js Client (Port 3000)                      │
└───────────────────────────────────┬────────────────────────────────────┘
                                    │ WebSockets (Socket.io)
                                    ▼
┌────────────────────────────────────────────────────────────────────────┐
│                        Express Server (Port 3002)                      │
│                                                                        │
│   ┌──────────────────────┐  ┌─────────────────┐  ┌──────────────────┐  │
│   │   Room Manager       │  │ Game State      │  │ Bot AI           │  │
│   │   (Room codes/joins) │  │ Sanitizer       │  │ (Active turns)   │  │
│   └──────────┬───────────┘  └────────┬────────┘  └────────┬─────────┘  │
└──────────────┼───────────────────────┼────────────────────┼────────────┘
               │                       │                    │
               ▼                       ▼                    ▼
┌──────────────────────────┐ ┌──────────────────┐ ┌──────────────────────┐
│  MongoDB Cloud Atlas     │ │ Game Engine      │ │ Local Redis Adapter  │
│  (User stats & balance)  │ │ (Rules & Deals)  │ │ (Scalable rooms)     │
└──────────────────────────┘ └──────────────────┘ └──────────────────────┘

🛠️ Technology Stack

  • Frontend: Next.js (React 19), Tailwind CSS v4, Framer Motion, Lucide React.
  • Backend: Express, Node.js, Socket.io, TypeScript, nodemon.
  • Data & Cache: Mongoose (MongoDB), ioredis (Redis Socket.io Adapter).
  • Game Logic: Pure TypeScript OOP engine (Game, Round, PlayerList, Hand, Deck, Card).

📂 Project Structure

durakgame/
├── app/                      # Next.js app router & UI components
│   ├── CreateGame.tsx        # Game configuration dashboard
│   ├── GameBoard.tsx         # Active table felt UI
│   ├── Leaderboard.tsx       # Live MongoDB score list
│   ├── PlayingCard.tsx       # Interactive card component
│   ├── PrivateGamesList.tsx  # Multiplayer lobby browser
│   ├── Profile.tsx           # User statistics & dossier
│   ├── global.css            # Tailwind stylesheets
│   ├── identity.ts           # Client identity profiles
│   ├── page.tsx              # Main viewport orchestrator
│   └── useDurak.ts           # Custom React hook for server messaging
├── src/                      # Core game logic
│   └── engine/               # TypeScript card game engine
│       ├── Card.ts           # Individual card schema
│       ├── Deck.ts           # Deck generation and dealing
│       ├── Game.ts           # Master Game orchestration class
│       ├── Hand.ts           # Hand management
│       ├── Player.ts         # Player instance tracking
│       └── Round.ts          # Attack/Defense round logic
├── server/                   # Node/Express backend
│   ├── index.ts              # Socket.io gateways & controllers
│   └── models/               # MongoDB Mongoose schemas
│       └── User.ts           # User balance & history schema
├── package.json
└── tsconfig.json

🚀 Getting Started

Prerequisites

  • Node.js (v18+)
  • MongoDB connection string (local or cloud)
  • Redis server running locally (Optional, falls back if Redis is not active)

1. Clone the repository

git clone https://github.com/ayberkince/durakgame.git
cd durakgame

2. Configure environment variables

Create a .env file in the server/ directory:

MONGODB_URI=mongodb+serif://username:password@your-cluster.mongodb.net/durak
PORT=3002

Create a .env.local file in the root directory:

NEXT_PUBLIC_SERVER_URL=http://localhost:3002

3. Install dependencies

npm install

4. Run the application (Hot-reload Development)

To boot both the Next.js frontend and Express/Socket.io backend concurrently:

npm run dev
  • Frontend runs at http://localhost:3000
  • Socket.io server runs at http://localhost:3002

🛡️ Executive Ruleset Details

Standard Mode

  • Each player is dealt 6 cards.
  • The lowest trump card holder begins the first round of attacks.
  • Attacker plays cards, Defender must beat them with a card of the same suit (but higher rank) or a Trump card.
  • If all cards are defended, they go to the discard pile. If the defender cannot defend, they must take all cards.

Transfer Mode (Perevodnoy)

  • If you are defending and have a card of the same rank as the attacking card, you can place it on the table to transfer the attack to the player on your left.
  • The player on your left must now defend against both cards (and any subsequent cards added to the attack).

📄 License

This project is licensed under the MIT License.

About

No description or website provided.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages