# 🚀 Crash Game - Get Started in 60 Seconds

## One-Stop Quick Start

### Prerequisites
- ✅ Go 1.18+
- ✅ Flutter 3.0+
- ✅ Port 8888 & 5000+ available

---

## 🎬 Start the System (2 Terminals)

### Terminal 1: Backend
```bash
cd "d:\flutter project\avi"
go run cmd/server/main.go
```
👉 You should see: `Starting server on :8888`

### Terminal 2: Frontend
```bash
cd "d:\flutter project\avi"
flutter run -d windows
```
👉 App opens automatically

---

## ✅ Verify It Works

1. **Look in top-right corner** → Should see green dot (connected) ✅
2. **Navigate to "Aviator Game"** → Click around ✅
3. **Click "🔄 New Round"** → Game starts ✅
4. **Enter amount** (e.g., 100) → Can type numbers ✅
5. **Enter cashout** (e.g., 2.5) → Can type numbers ✅
6. **Click "🚀 Place Bet"** → Multiplier increases in real-time ✅
7. **Watch the multiplier** → Updates every 50ms ✅
8. **Click "⏸️ Cash Out"** → Game stops, you cash out ✅

---

## 📱 Test API with cURL (Optional)

```bash
# Start a round
curl -X POST http://localhost:8888/api/v1/game/round/start \
  -H "X-User-ID: testuser"

# Place a bet (use round ID from above)
curl -X POST http://localhost:8888/api/v1/game/bet \
  -H "X-User-ID: testuser" \
  -H "Content-Type: application/json" \
  -d '{
    "round_id": "YOUR_ROUND_ID",
    "amount": 100,
    "auto_cashout_multiplier": 2.5
  }'
```

---

## 🎯 Game Rules (Quick Overview)

| Rule | Value |
|------|-------|
| Duration | 7 seconds max |
| Multiplier Range | 1.0x → 7.0x |
| Crash Point | Random (500-6800ms) |
| Win | Cash out before crash |
| Loss | Don't cash out before crash |
| Payout | Bet × Multiplier |

---

## 🔴 Something Wrong?

### Red X instead of Green Dot?
```bash
# Make sure backend is running
curl http://localhost:8888/health
```

### App won't start?
```bash
# Get dependencies
flutter pub get

# Then try again
flutter run -d windows
```

### Backend won't start?
```bash
# Check if port 8888 is free
netstat -ano | findstr :8888

# Kill if needed (Windows)
taskkill /PID <PID> /F
```

See [CRASH_GAME_TROUBLESHOOTING.md](CRASH_GAME_TROUBLESHOOTING.md) for more issues.

---

## 📚 Need More Help?

| Question | Document |
|----------|----------|
| How do I deploy? | [CRASH_GAME_FULL_DEPLOYMENT_GUIDE.md](CRASH_GAME_FULL_DEPLOYMENT_GUIDE.md) |
| API endpoints? | [CRASH_GAME_BACKEND_INTEGRATION.md](CRASH_GAME_BACKEND_INTEGRATION.md) |
| How does the game work? | [CRASH_GAME_IMPLEMENTATION_SUMMARY.md](CRASH_GAME_IMPLEMENTATION_SUMMARY.md) |
| Issues? | [CRASH_GAME_TROUBLESHOOTING.md](CRASH_GAME_TROUBLESHOOTING.md) |
| Quick reference? | [CRASH_GAME_DEVELOPER_QUICK_REFERENCE.md](CRASH_GAME_DEVELOPER_QUICK_REFERENCE.md) |

---

## 🎯 File Structure

```
d:\flutter project\avi\
├── backend/
│   └── cmd/server/main.go          ← Backend entry point
│   └── internal/
│       ├── handlers/               ← API handlers
│       ├── services/               ← Game logic
│       └── models/                 ← Data models
│
├── lib/
│   ├── data/
│   │   ├── services/               ← API client
│   │   └── providers/              ← State management
│   └── presentation/
│       ├── screens/
│       │   └── game/aviator_game_screen.dart  ← Main game screen
│       └── widgets/                           ← Game widgets
│
└── [7 Documentation Files]
```

---

## 🚀 Common Commands

```bash
# Backend
go run cmd/server/main.go              # Start server
go mod tidy                             # Clean dependencies
go mod download                         # Download all deps

# Frontend
flutter run -d windows                  # Run on Windows
flutter run -d chrome                   # Run on Web
flutter pub get                         # Get dependencies
flutter pub upgrade                     # Update packages
flutter clean                           # Clean build cache

# Testing
curl http://localhost:8888/health       # Health check
wscat -c ws://localhost:8888/api/v1/game/ws  # WebSocket test
```

---

## ✨ What's Included

✅ **Backend** - Complete Go server with 5 API endpoints  
✅ **Frontend** - Flutter app with real-time UI updates  
✅ **WebSocket** - Real-time multiplier broadcasting (50ms intervals)  
✅ **Database** - GORM ORM with auto-migrations  
✅ **Security** - Server-side crash generation (fair game)  
✅ **Documentation** - 7 comprehensive guides  
✅ **Error Handling** - Complete error recovery system  

---

## 💡 Pro Tips

1. **Adjust Backend URL**: If not on localhost, edit:
   - `lib/data/services/backend_api_service.dart` (HTTP)
   - `lib/data/providers/websocket_provider.dart` (WebSocket)

2. **Use REST for Testing**: Start with cURL before frontend

3. **Watch Logs**: Both terminal windows show detailed logs

4. **Reset Game**: Kill both processes Ctrl+C, restart both

---

## 🎉 You're Ready!

```bash
# Just 2 commands needed:

# Backend (Terminal 1)
go run cmd/server/main.go

# Frontend (Terminal 2)  
flutter run -d windows

# Then open the Aviator Game and place bets! 🎮
```

---

**Questions?** See the documentation files in the project root.  
**Issues?** Check [CRASH_GAME_TROUBLESHOOTING.md](CRASH_GAME_TROUBLESHOOTING.md).  
**Ready to deploy?** Follow [CRASH_GAME_FULL_DEPLOYMENT_GUIDE.md](CRASH_GAME_FULL_DEPLOYMENT_GUIDE.md).
