{"id":30050039,"url":"https://github.com/jeeyo/battleship-p2p","last_synced_at":"2026-06-30T09:31:23.751Z","repository":{"id":306116946,"uuid":"1024802907","full_name":"jeeyo/battleship-p2p","owner":"jeeyo","description":"A \"vibe\" WebRTC-based P2P online Battleship game, with Cloudflare Workers as signaling server","archived":false,"fork":false,"pushed_at":"2025-10-31T20:24:31.000Z","size":271,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-31T20:25:31.766Z","etag":null,"topics":["cloudflare-workers","durable-objects","p2p","webrtc","websocket"],"latest_commit_sha":null,"homepage":"https://battleship-p2p.jeeyo.workers.dev/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jeeyo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-23T09:14:52.000Z","updated_at":"2025-10-31T20:24:35.000Z","dependencies_parsed_at":"2025-07-23T20:09:40.721Z","dependency_job_id":"cf4bfdd2-63fc-4940-b51c-d95f87f54a80","html_url":"https://github.com/jeeyo/battleship-p2p","commit_stats":null,"previous_names":["jeeyo/battleship-p2p"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jeeyo/battleship-p2p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeeyo%2Fbattleship-p2p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeeyo%2Fbattleship-p2p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeeyo%2Fbattleship-p2p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeeyo%2Fbattleship-p2p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeeyo","download_url":"https://codeload.github.com/jeeyo/battleship-p2p/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeeyo%2Fbattleship-p2p/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34961543,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-30T02:00:05.919Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-workers","durable-objects","p2p","webrtc","websocket"],"created_at":"2025-08-07T13:01:24.924Z","updated_at":"2026-06-30T09:31:23.744Z","avatar_url":"https://github.com/jeeyo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# P2P Battleship Game\n\nA modern, web-based Battleship game that uses WebRTC for peer-to-peer gameplay. Players can create or join games using room codes, place their ships, and battle it out in real-time without the need for a central game server.\n\nDemo: https://battleship-p2p.jeeyo.workers.dev/\n\n## Features\n\n- 🚢 **Classic Battleship Gameplay**: Place 5 ships and try to sink your opponent's fleet\n- 🔗 **Peer-to-Peer Multiplayer**: Direct connection between players using WebRTC\n- 🎮 **Real-time Gameplay**: Instant moves and responses\n- 📱 **Responsive Design**: Works on desktop and mobile devices\n- 🎨 **Modern UI**: Beautiful, animated interface with visual feedback\n- 🔐 **Simple Room System**: 6-character room codes for easy game sharing\n- 🌊 **Interactive Ship Placement**: Click to place and rotate ships with visual validation\n- 📊 **Game Statistics**: Track shots fired and ships remaining\n- ⚡ **Flexible Ship Placement**: Ships can be placed adjacent to each other for strategic positioning\n- 📱 **PWA Support**: Installable as a Progressive Web App for offline access\n\n## Technology Stack\n\n- **Frontend**: HTML5, CSS3, JavaScript (ES6+)\n- **Networking**: WebRTC for P2P communication\n- **Signaling**: Cloudflare Workers + Durable Objects (WebSocket)\n- **Styling**: CSS Grid, Flexbox, CSS Variables\n- **Game Logic**: Object-oriented JavaScript\n\n## Game Rules\n\n1. Each player places 5 ships on a 10x10 grid:\n   - Carrier (5 squares)\n   - Battleship (4 squares)\n   - Cruiser (3 squares)\n   - Submarine (3 squares)\n   - Destroyer (2 squares)\n\n2. Ships cannot overlap but can be placed adjacent to each other\n3. Players alternate turns attacking opponent's grid coordinates\n4. Turns switch after every shot regardless of hit or miss\n5. First player to sink all enemy ships wins\n\n## Quick Start\n\n### For Local Development\n\n1. **Clone and Setup**:\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd battleship-p2p\n   npm install\n   ```\n\n2. **Start Development Server**:\n   ```bash\n   # Start local Cloudflare Worker (Durable Objects + static assets)\n   npm run dev:worker\n   ```\n   This serves the Worker on port 8787 and the static assets from `dist/`.\n\n3. **Open in Browser**:\n   Navigate to `http://localhost:8787`\n\n### Deploying to Cloudflare Workers\n\n1. **Install Wrangler CLI** (if not already installed):\n   ```bash\n   npm install -g wrangler\n   ```\n\n2. **Login to Cloudflare**:\n   ```bash\n   wrangler login\n   ```\n\n3. **Deploy to Cloudflare Workers**:\n   ```bash\n   npm run deploy:worker\n   ```\nThe Worker serves both the signaling WebSocket and the static site.\n\n## File Structure\n\n```\nbattleship-p2p/\n├── dist/                    # Built game files\n│   ├── index.html          # Main HTML structure\n│   ├── styles.css          # CSS styling and animations\n│   ├── game-logic.js       # Core Battleship game logic\n│   ├── webrtc.js          # WebRTC connection management\n│   ├── app.js             # Main application controller\n│   ├── sw.js              # Service worker for offline support\n│   ├── manifest.json       # PWA manifest\n│   └── favicon-*.png       # App icons\n├── src/\n│   └── worker.js          # Cloudflare Worker entry with Durable Object\n├── .github/\n│   └── workflows/\n│       └── worker-deployment.yaml  # CI/CD deployment workflow\n├── package.json           # Node.js dependencies\n├── wrangler.toml         # Cloudflare Workers configuration\n└── README.md             # This file\n```\n\n## How to Play\n\n1. **Start a Game**:\n   - Click \"Create New Game\" to host a game and get a room code\n   - Or enter a room code and click \"Join Game\"\n\n2. **Place Your Ships**:\n   - Click on a ship type to select it\n   - Click on the board to place it\n   - Use \"Rotate Ship\" to change orientation between horizontal and vertical\n   - Use \"Random Placement\" for quick automatic setup\n   - Use \"Clear Board\" to remove all placed ships\n   - Click \"Ready!\" when all ships are placed\n\n3. **Battle Phase**:\n   - Click on the enemy board to attack\n   - Red squares with 🔥 indicate hits\n   - Gray squares with 💧 indicate misses\n   - Black squares with 💀 indicate sunk ships\n   - Turns alternate after every shot\n   - First to sink all enemy ships wins!\n\n## Development\n\n### Adding Features\n\nThe codebase is modular and extensible:\n\n- **Game Logic**: Modify `BattleshipGame` class in `dist/game-logic.js`\n- **UI Components**: Update HTML structure in `dist/index.html` and CSS styling in `dist/styles.css`\n- **Networking**: Extend `WebRTCManager` class in `dist/webrtc.js`\n- **Application Flow**: Modify `BattleshipApp` class in `dist/app.js`\n- **Worker Endpoints**: Add new endpoints in `src/worker.js`\n\n### Key Classes\n\n- **`BattleshipGame`**: Core game mechanics, ship placement, attack logic\n- **`WebRTCManager`**: P2P connection setup and data transmission\n- **`BattleshipApp`**: UI controller and game state management\n\n### WebRTC Flow\n\n1. Room creation/joining via Cloudflare Workers (Durable Objects)\n2. WebSocket signaling connection to Durable Object for room coordination\n3. Signaling message exchange (offers, answers, ICE candidates) via WebSocket\n4. Direct P2P data channel establishment (reliable control channel + unreliable inputs channel)\n5. Game data transmission over data channels\n6. Turn synchronization messages to maintain game state\n\n### Worker Endpoints\n\n- `GET /health` - Health check endpoint\n- `GET /turn-credentials` - Returns ICE/TURN server configuration\n- `POST /metrics` - Metrics/analytics endpoint (optional)\n- `WS /ws/:roomCode` - WebSocket signaling via Durable Object for room coordination\n\n## Browser Compatibility\n\n- Chrome 70+\n- Firefox 65+\n- Safari 12+\n- Edge 79+\n\nWebRTC is required for P2P functionality.\n\n## Known Limitations\n\n1. **No Reconnection**: If connection drops, players need to start a new game\n2. **No Persistence**: Game state is not persisted; rooms are temporary\n3. **No Spectators**: Only 2 players per room supported\n4. **No AI**: Human opponent required\n\n### Debug Mode\n\nOpen browser developer tools and check the console for detailed connection and game state information.\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Test thoroughly in both development and production environments\n5. Submit a pull request\n\n## Recent Changes\n\n- **Code Cleanup**: Removed unused code and methods for cleaner codebase\n- **Adjacent Ship Placement**: Ships can now be placed touching each other\n- **Turn Mechanics**: Players alternate after every shot (not just misses)\n- **Improved Synchronization**: Better turn state management between players\n- **Board Bug Fixes**: Fixed issues with cell state management\n- **Cloudflare Workers**: Migrated from Cloudflare Pages to Workers with Durable Objects\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n\n## Credits\n\n- Game concept: Classic Battleship board game\n- Icons: Emoji characters for visual feedback\n- Networking: WebRTC and Cloudflare Workers\n\n---\n\n**Enjoy your naval battles! ⚓** \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeeyo%2Fbattleship-p2p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeeyo%2Fbattleship-p2p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeeyo%2Fbattleship-p2p/lists"}