Skip to content

pacphi/battleship

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

27 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒŠ Battleship P2P ๐Ÿš€

CI Security Audit License: MIT

Drop in. Aim true. Sink everything. ๐Ÿ”ฅ

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.


๐Ÿ”ฅ Why You'll Love It

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

๐Ÿ› ๏ธ How to Play in 30 Seconds

  1. Open the game URL in any modern browser ๐Ÿ–ค๏ธ
  2. Create a game (or join with a code)
  3. 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.
  4. Share the 6-char code with your opponent via chat, DM, or carrier pigeon ๐Ÿ•Š
  5. Click to fire. Sink all 6 ships to win. โš”๏ธ

The Fleet

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!

๐Ÿš€ Quick Start

# Install dependencies
pnpm install

# Start the Astro dev server
pnpm dev            # 🎲️  http://localhost:4321

For local multiplayer testing, also start the single-origin production-style server after building:

pnpm build
pnpm server         # 🔍  http://localhost:4321 with /signaling WebSocket

Open two browser tabs, create a game in one, join with the code in the other. Done. ๐ŸŽ‰

Host friends over a tunnel

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 check

Prefer 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

zrok installs project-local into .tools/ (checksum-verified); ngrok installs 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 setup

๐Ÿ’พ Under the Hood

Browser (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 requestAnimationFrame loop
  • Zero dependencies on UI frameworks โ€” just pure, performant JS

๐Ÿ“š Documentation

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:setup and 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.

๐Ÿงช Tech Stack

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

โš™๏ธ Scripts

# &#x1F3D7;&#xFE0F;  Build & run
pnpm dev          # &#x1F3B2;&#xFE0F;  Astro dev server
pnpm build        # &#x1F4E6;  production bundle
pnpm preview      # &#x1F440;  local preview of build
pnpm server       # &#x1F50D;  static site + /signaling WebSocket

# &#x1F9ED;  Host friends over a tunnel (see docs/HOSTING.md for the walkthrough)
pnpm tunnel:setup             # &#x1F9ED;  guided: pick a tunnel, sign in, host
pnpm tunnel:doctor            # &#x1FA7A;  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

# &#x2705;  Quality gates (see docs/MAINTAINERS.md โ†’ Developer workflow)
pnpm test         # &#x1F9EA;  run all tests once
pnpm test:watch   # &#x1F441;&#xFE0F;   re-run tests on change
pnpm typecheck    # &#x1F50E;  astro check (TS + template types)
pnpm lint         # &#x1F9E1;  ESLint
pnpm lint:fix     # &#x1F527;  ESLint with autofix
pnpm format       # &#x1F4BE;  Prettier across everything
pnpm format:check # &#x1F4CF;  Prettier in check-only mode
pnpm lint:md      # &#x1F4D6;  Markdown lint (markdownlint-cli2)
pnpm lint:md:fix  # &#x1F4DD;  Markdown lint with autofix
pnpm check        # &#x2705;  typecheck + lint + format:check + test
pnpm fix          # &#x1F9F9;  lint:fix + format (auto-clean everything)

# &#x1F4E6;  Dependency hygiene
pnpm audit            # &#x1F6E1;&#xFE0F;   report known vulnerabilities (also runs weekly in CI)
pnpm audit:fix        # &#x1F527;  apply available audit fixes
pnpm deps:outdated    # &#x1F4C5;  list outdated dependencies
pnpm deps:update      # &#x2B06;&#xFE0F;   update within semver ranges
pnpm deps:update:latest  # &#x1F680;  update to latest (may break)

๐ŸŽฏ Ship It

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.


๐Ÿ” License

MIT โ€” go forth and wage naval warfare. ๐Ÿš€๐ŸŒŠ

About

A P2P engine adapted for the game of Battleship

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors