Skip to content
laozhejPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HexWar

A hex-based naval strategy game built with vanilla HTML5 Canvas and JavaScript. Play in-browser with no dependencies — just open and play.

HexWar Screenshot License

Features

  • Hexagonal Grid — Pointy-top hex map with sea, land, and mountain terrain
  • Fog of War — Terrain visible through fog, units hidden until spotted
  • Economy — Towns generate money, factories produce materials, with encirclement production bonuses
  • Naval Units — Warship (anti-sub), Submarine (stealth), Aircraft Carrier (colonize), Colony Ship
  • Land Structures — Main Base, Town, Factory, Naval Base, Airport, Radar, Coastal Gun, AA Gun
  • Combat — Counter-attacks, passive destruction, submarine stealth, AA suppression
  • AI Opponents — Easy, Medium, and Extreme difficulty levels
  • Map Editor — Create and save custom maps with terrain painting and base placement
  • Full Customization — Edit all unit/building stats, share config codes, save templates per player
  • Save/Load — Save games to browser storage and resume later
  • Statistics — Track economy and military performance with charts
  • Multiplayer — Online play via WebSocket (requires server)
  • Cross-Platform — Works on desktop and mobile browsers

Quick Start

Option A — Open directly (no server needed):

  1. Run python build.py to generate game.html
  2. Open game.html in your browser

Option B — With ES modules (local server):

  1. Serve the project folder with any HTTP server:
    python -m http.server 8080
  2. Open http://localhost:8080 in your browser

Controls

Input Action
Left click Select / Move / Attack / Build
Right click drag Pan camera
Scroll wheel Zoom in/out
1-7 Quick-select building type
E End turn
Escape Deselect
Ctrl+Z Undo last action
Tab Toggle statistics

Touch controls are supported on mobile (tap to select, drag to pan, pinch to zoom).

Multiplayer

  1. Start the WebSocket server:
    cd server
    npm install
    node server.js
  2. In-game, select Online mode and connect to the server URL
  3. Create or join a room with the 6-character room code

Project Structure

index.html          — Main HTML (ES module version)
css/style.css       — Styles and responsive layout
js/
  hex.js            — Hex grid math (coordinates, pathfinding, line of sight)
  config.js         — Game configuration and data templates
  gameState.js      — Core game engine (turns, combat, economy, fog)
  renderer.js       — Canvas renderer (terrain, units, buildings, UI)
  ai.js             — AI system (easy/medium/extreme)
  multiplayer.js    — WebSocket multiplayer client
  main.js           — Application controller and UI
server/
  server.js         — WebSocket multiplayer server (Node.js)
build.py            — Bundles JS into standalone game.html for offline use

Building

python build.py

This generates:

  • js/bundle.js — All JS concatenated into a single non-module script
  • game.html — Standalone HTML that works via file:// protocol

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages