# Setup Instructions for 1v1 FPS Server

## Prerequisites Installation (Windows)

### Step 1: Install Node.js
1. Download from https://nodejs.org/ (LTS version recommended)
2. Run the installer
3. Use default options
4. **Verify installation:**
   ```powershell
   node --version
   npm --version
   ```

### Step 2: Install PostgreSQL
1. Download from https://www.postgresql.org/download/windows/
2. Run installer, remember the password you set
3. Keep port as 5432 (default)
4. **Verify installation:**
   ```powershell
   psql --version
   ```

## Project Setup

### Step 3: Setup Backend

Open PowerShell and navigate to the backend folder:

```powershell
cd "c:\Users\07ear01\Documents\1v1\backend"

# Install dependencies
npm install

# Create .env file from template
Copy-Item .env.example .env

# Edit .env file with your database credentials
notepad .env
```

In the `.env` file, ensure these values:
```
PORT=3000
DATABASE_URL=postgresql://postgres:PASSWORD@localhost:5432/fps_1v1
NODE_ENV=development
```
Replace `PASSWORD` with what you set during PostgreSQL installation.

### Step 4: Setup Database

```powershell
# Create database
psql -U postgres -c "CREATE DATABASE fps_1v1;"

# Load schema
psql -U postgres -d fps_1v1 -f "c:\Users\07ear01\Documents\1v1\backend\src\db\schema.sql"
```

### Step 5: Setup Frontend

Open another PowerShell window:

```powershell
cd "c:\Users\07ear01\Documents\1v1\frontend"

# Install dependencies
npm install
```

## Running the Application

### Terminal 1: Start Backend Server
```powershell
cd "c:\Users\07ear01\Documents\1v1\backend"
npm run dev
```
Expected output: 🎮 Game server running on ws://0.0.0.0:3000

### Terminal 2: Start Frontend Dev Server
```powershell
cd "c:\Users\07ear01\Documents\1v1\frontend"
npm start
```
Expected output: Webpack dev server running on http://localhost:8080

### Step 6: Test the Game

1. Open browser to http://localhost:8080
2. Enter player name
3. Click "Play" button
4. Open another browser window/tab to http://localhost:8080
5. Enter different player name
6. Click "Play" - should match both players together
7. Game should start!

## Troubleshooting

**Error: "Cannot connect to server"**
- Make sure backend (Terminal 1) is running
- Check the output shows: "🎮 Game server running"

**Error: "Database connection failed"**
- Verify PostgreSQL is running
- Check DATABASE_URL in .env matches your setup
- Test connection: `psql -U postgres -d fps_1v1`

**Port already in use (3000 or 8080)**
- Change PORT in backend .env to 3001, 3002, etc
- Update frontend network.ts to match new port

## Next: Build for Production

After testing locally:

```powershell
# Backend
cd backend
npm run build

# Frontend
cd frontend
npm run build
```

Generated files ready to deploy to cloud!
