Battleship, the classic naval combat game โ reborn for the modern web. No downloads. No accounts. Just open a link, share a code, and wage full-on fleet war against a friend. ๐ ๏ธ
โก Built with Astro, WebRTC, and pure vanilla JS โ all game data flows peer-to-peer between browsers. Zero server-side game logic. Maximum privacy. Minimum latency.
| Feature | The Deal |
|---|---|
| ๐งก True P2P | Your shots never touch a game server โ browsers connect directly via WebRTC |
| ๐ Zero Sign-Up | Open the URL. Pick a mode. Share a 6-character code. That's it. |
| ๐ฅ Three Game Modes | Round-Based for fast-fire thrills, Queue-Based for chill tactical play, Hybrid for the best of both |
| ๐ Special Ships | Sneaky submarines that hide until first hit. Shifting torpedo boats that dodge after a miss. |
| ๐จ Canvas Graphics | Smooth HTML5 Canvas rendering with fire & splash animations |
| ๐ LAN-Ready | Works on your home network, at a hackathon, or across the globe |
- Open the game URL in any modern browser ๐ค๏ธ
- Create a game (or join with a code)
- Pick your mode:
- โฑ๏ธ Round-Based โ 3-second timer per round. Fast decisions. Who blinks first?
- ๐ฆ Queue-Based โ Fire whenever you're ready. No pressure. Maximum strategy.
- ๐ Hybrid โ Timer + grace period. Structure and flexibility.
- Share the 6-char code with your opponent via chat, DM, or carrier pigeon ๐
- Click to fire. Sink all 6 ships to win. โ๏ธ
| Ship | Size | ๐ฏ Special Ability |
|---|---|---|
| ๐ Carrier | 5 cells | Classic heavy hitter |
| ๐ข Battleship | 4 cells | Second only to the carrier in power |
| ๐ฃ๏ธ Heavy Cruiser | 3 cells | Solid workhorse of the fleet |
| ๐ฃ๏ธ Light Cruiser | 3 cells | Agile and versatile |
| ๐ฒ Submarine | 2 cells | Hidden until first hit โ invisible threat! |
| ๐ฅ Torpedo Boat | 2 cells | Shifts position after a miss โ never still for long! |
# Install dependencies
pnpm install
# Start the Astro dev server
pnpm dev # 🎲️ http://localhost:4321For local multiplayer testing, also start the single-origin production-style server after building:
pnpm build
pnpm server # 🔍 http://localhost:4321 with /signaling WebSocketOpen two browser tabs, create a game in one, join with the code in the other. Done. ๐
Want a friend on another computer to join? Run the guided setup โ it picks a tunnel, signs you in, and opens one public link to share:
pnpm tunnel:setup # interactive: pick zrok/ngrok, install, sign in, host
pnpm tunnel:doctor # friendly "is everything ready?" health checkPrefer to do it by hand?
pnpm tunnel:install:zrok # project-local, checksum-verified
.tools/bin/zrok2 enable <token> # one-time sign-in (see the Hosting guide)
pnpm tunnel:zrok # build, serve, and open a zrok tunnel
pnpm tunnel:install:ngrok # system-wide via your OS package manager
ngrok config add-authtoken <token>
pnpm tunnel:ngrok
zrokinstalls project-local into.tools/(checksum-verified);ngrokinstalls system-wide via your OS package manager. The Hosting guide explains why, where to get a free token, and how to troubleshoot.
Windows users run the PowerShell helper directly:
.\scripts\tunnel-setup.pwsh setupBrowser (Player 1) <โโโโโโโโ WebRTC P2P โโโโโโโโโบ Browser (Player 2)
โฒ โฒ
โ Signaling handshake only (SDP + ICE) โ
โโโโโโโโโโโ Node.js / WebSocket โโโโโโโโโโโโโโโโโโ
- Game state lives entirely in each player's browser ๐งฐ
- Signaling server handles only the initial WebRTC handshake on
/signalingโ it never sees a single move - Rendering via vanilla HTML5 Canvas with
requestAnimationFrameloop - Zero dependencies on UI frameworks โ just pure, performant JS
Want a feel for the game first? Take the ๐ธ Screenshots tour โ a few annotated shots from start screen to firing the first salvo.
Start at the Guide index โ it routes you by what you want to do:
- ๐ฎ Playing โ a friend sent you a link or a code. Zero setup, just a browser.
- ๐ Hosting โ invite friends to play online. Run
pnpm tunnel:setupand it walks you through everything. - ๐ Deploying โ put the game on a real web address (static
dist/+ signaling). - ๐ฑ Seed โ run the game natively on a Cognitum One Seed device as a self-contained Rust cog.
- ๐ง Maintainer Docs โ project setup, architecture overview, testing, and release process.
| Layer | Tech |
|---|---|
| ๐จ Pages | Astro (static output) |
| ๐น๏ธ Rendering | HTML5 Canvas (vanilla JS) |
| ๐ Networking | WebRTC DataChannel (P2P) |
| ๐ Signaling | Node.js ws WebSocket |
| ๐ฏ Styling | Pure CSS |
| ๐งช Testing | Vitest |
# 🏗️ Build & run
pnpm dev # 🎲️ Astro dev server
pnpm build # 📦 production bundle
pnpm preview # 👀 local preview of build
pnpm server # 🔍 static site + /signaling WebSocket
# 🧭 Host friends over a tunnel (see docs/HOSTING.md for the walkthrough)
pnpm tunnel:setup # 🧭 guided: pick a tunnel, sign in, host
pnpm tunnel:doctor # 🩺 health check: is everything ready to host?
pnpm tunnel:install:zrok # project-local, checksum-verified
pnpm tunnel:uninstall:zrok
pnpm tunnel:install:ngrok # system-wide (user scope, via package manager)
pnpm tunnel:uninstall:ngrok
pnpm tunnel:zrok # build, serve, open a zrok tunnel
pnpm tunnel:ngrok # build, serve, open an ngrok tunnel
# ✅ Quality gates (see docs/MAINTAINERS.md โ Developer workflow)
pnpm test # 🧪 run all tests once
pnpm test:watch # 👁️ re-run tests on change
pnpm typecheck # 🔎 astro check (TS + template types)
pnpm lint # 🧡 ESLint
pnpm lint:fix # 🔧 ESLint with autofix
pnpm format # 💾 Prettier across everything
pnpm format:check # 📏 Prettier in check-only mode
pnpm lint:md # 📖 Markdown lint (markdownlint-cli2)
pnpm lint:md:fix # 📝 Markdown lint with autofix
pnpm check # ✅ typecheck + lint + format:check + test
pnpm fix # 🧹 lint:fix + format (auto-clean everything)
# 📦 Dependency hygiene
pnpm audit # 🛡️ report known vulnerabilities (also runs weekly in CI)
pnpm audit:fix # 🔧 apply available audit fixes
pnpm deps:outdated # 📅 list outdated dependencies
pnpm deps:update # ⬆️ update within semver ranges
pnpm deps:update:latest # 🚀 update to latest (may break)Deploy the static dist/ folder to any static hosting provider and run server/index.mjs anywhere that can serve WebSockets:
- ๐ถ GitHub Pages โ use the included CI workflow
- โ๏ธ Netlify / Vercel โ connect repo, build cmd:
pnpm build - โ๏ธ Cloudflare Pages โ same build command
- โ๏ธ S3 + CloudFront โ upload
dist/as a static website - ๐ฑ Cognitum One Seed โ build the Rust cog (
cross build --release) and register it on the device; no Node.js required
For LAN parties and demos, pnpm server serves both the static build and signaling on one port.
MIT โ go forth and wage naval warfare. ๐๐