An immersive, web-based D&D-like game powered by AI storytelling and a code-based rule engine.
- ๐ค AI-Powered Narrative: OpenAI GPT-4 generates immersive story descriptions
- โ๏ธ Rule Engine: All game mechanics (dice rolls, combat, skill checks) are handled by code
- ๐ฒ D&D Mechanics: Real dice rolling, ability scores, AC, HP, XP, and leveling
- ๐จ Beautiful UI: Immersive dark theme with smooth animations
- ๐ฑ Responsive Design: Works on desktop and mobile devices
- ๐ฎ Freeform Actions: Type anything you want to do in natural language
- ๐ Easy Setup: One-click startup with .env configuration
- Python 3.8+
- Node.js 16+
- AI API key (see options below)
-
Copy the example environment file:
# Windows copy .env.example .env # Linux/Mac cp .env.example .env
-
Edit
.envfile and add your API key:AI_PROVIDER=openai OPENAI_API_KEY=sk-your-key-here
Or use a free option:
AI_PROVIDER=groq GROQ_API_KEY=gsk-your-key-here
-
Install dependencies:
# Backend cd backend pip install -r requirements.txt # Frontend cd ../frontend npm install
Windows:
start.batLinux/Mac:
chmod +x start.sh
./start.shManual (if scripts don't work):
# Terminal 1 - Backend
cd backend
python app.py
# Terminal 2 - Frontend
cd frontend
npm run devThen open http://localhost:3000 in your browser!
- Go to https://console.groq.com/
- Sign up (no credit card needed)
- Create API key
- Add to
.env:GROQ_API_KEY=gsk-your-keyandAI_PROVIDER=groq
- Go to https://platform.openai.com/api-keys
- Sign up and add payment method
- Create API key
- Add to
.env:OPENAI_API_KEY=sk-your-keyandAI_PROVIDER=openai
See .env.example for Ollama, Hugging Face, and Together AI options.
-
Open
http://localhost:3000in your browser -
Type your actions in natural language:
- "attack the goblin"
- "search the room"
- "move north"
- "climb the wall"
- "rest and heal"
- Or anything creative you can think of!
-
The AI will narrate what happens based on your actions
-
The rule engine handles all dice rolls, combat, and game mechanics
-
Watch your stats, level up, and explore the dungeon!
- FastAPI server for REST API
- Rule Engine: Handles all game mechanics (dice, combat, skills)
- AI Integration: Generates narrative descriptions
- Game State Management: Tracks character, inventory, monsters, etc.
- .env Configuration: Loads API keys from
.envfile automatically
- React with Vite for fast development
- Modern UI with immersive dark theme
- Real-time Updates: Shows narrative, events, and game state
- Responsive Design: Works on all screen sizes
- Attack rolls use d20 + strength modifier + proficiency
- Damage rolls use d6 + strength modifier
- Critical hits on natural 20
- AC determines hit chance
- Ability checks use d20 + ability modifier + proficiency
- Difficulty Class (DC) determines success
- Advantage can be granted for certain actions
- Gain XP from defeating monsters
- Level up automatically when XP threshold is reached
- HP increases on level up
- Proficiency bonus increases with level
.
โโโ .env # Your API keys (create from .env.example)
โโโ .env.example # Example configuration file
โโโ start.bat # Windows startup script
โโโ start.sh # Linux/Mac startup script
โโโ backend/
โ โโโ app.py # FastAPI server and game logic
โ โโโ requirements.txt # Python dependencies
โโโ frontend/
โ โโโ src/
โ โ โโโ App.jsx # Main React component
โ โ โโโ App.css # Styles
โ โ โโโ main.jsx # React entry point
โ โ โโโ index.css # Global styles
โ โโโ index.html # HTML template
โ โโโ package.json # Node dependencies
โ โโโ vite.config.js # Vite configuration
โโโ README.md # This file
Create a .env file in the project root:
AI_PROVIDER=openai
OPENAI_API_KEY=sk-your-key-hereThe backend automatically loads this file on startup. No need to set environment variables manually!
- Default port:
8000 - Change in
app.py:uvicorn.run(app, host="0.0.0.0", port=8000)
- Default port:
3000 - API proxy configured in
vite.config.js - Change API base URL with environment variable:
VITE_API_BASE
Edit Character.__init__() in backend/app.py
All game rules are in the RuleEngine class in backend/app.py
Edit the get_dm_prompt() function in backend/app.py
Modify frontend/src/App.css for UI changes
Backend won't start:
- Check Python version:
python --version(need 3.8+) - Install dependencies:
pip install -r requirements.txt - Check
.envfile exists and has valid API key
Frontend won't start:
- Check Node version:
node --version(need 16+) - Install dependencies:
npm install - Clear cache:
rm -rf node_modules && npm install
API errors:
- Verify
.envfile has correct API key - Check backend terminal for error messages
- Verify API key is valid and has credits
Port already in use:
- Backend: Change port in
app.pyor stop process using port 8000 - Frontend: Change port in
vite.config.jsor stop process using port 3000
To share this game with others:
-
They only need to:
- Copy
.env.exampleto.env - Add their API key to
.env - Run
start.bat(Windows) or./start.sh(Linux/Mac)
- Copy
-
That's it! No manual environment variable setup needed.
The .env file is in .gitignore so API keys won't be committed to git.
MIT License - Feel free to use and modify!
Built with:
- FastAPI
- React
- Vite
- OpenAI GPT-4 / Groq
- Lots of imagination! ๐ฒ