Public: anyone can read this; the crew can change it.

Migrated from github.com/amirmushichge/pixel-plays

Add Market Barrow: the playable page and its place in the catalogue, on the rules in `market-barrow/barrow.js` #206

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

vesper/pixel-plays:vesper/169-add-market-barrow-the-playable-page-and → main 7 commits fork 4 threads · 4 unresolved

  • Merged. vesper/169-add-market-barrow-the-playable-page-and was merged into main as 9a10fcc.

Review

Sign in to review this change.
9 files changed +518 −2
README.md +3 −2
@@ -51,6 +51,7 @@ Concept by [abhi](https://x.com/awwbhi2). Game by [AmirMushich](https://x.com/Am
5151 | [Dinghy Race](dinghy-race/) | A bay with a square course of three buoys and back over a start line, the wind from the south-east and shifting a little at each buoy: the boat steers itself buoy to buoy and you trim the sail; it drives best at half the angle between boat and wind, and loses speed quadratically as the trim drifts from that, so every leg and every wind shift asks for a new setting; two seeded rivals sail at a steady pace, first or second place is a win (forged by the crew on the engine and shell above, not by the original creators; rules in `dinghy-race/dinghy.js`) | Drag left and right along the sheet; Up and Down arrows trim in and out |
5252 | [Seed Packets](seed-packets/) | A potting-shed bench with sixteen face-down seed packets in a 4x4 grid, a watering can and a clock on the wall: tap a packet to turn it face up to show its flower, then a second; a matching pair stays face up and a mismatch turns both back after 0.8 s (taps in that beat are ignored); the layout is a seeded shuffle of eight pairs and the gardener returns after 16 turns (a turn is two packets), so you can afford eight mismatches; the end shows pairs found and turns used, and the best is the fewest turns in a win (forged by the crew on the engine and shell above, not by the original creators) | Tap; arrows + space |
5353 | [Ferryman](ferryman/) | A river with a near bank, a far bank and a ferry moored at the near landing: tap a passenger to load or unload it, then tap the ferry to cross (or press 1-4 to pick a passenger and Space to cross); the fox, the goose and the grain start on the near bank, and left alone together on a bank the fox eats the goose and the goose eats the grain, so the ferry carries one at a time; three levels, the later ones add a dog, a two-seat ferry and a crossing limit, and a round is won by getting everyone across in par crossings or fewer, the HUD showing level, crossings and par as the rules report them (forged by the crew on the engine and shell above, not by the original creators; rules in `ferryman/ferry.js`) | Tap; 1-4 and Space |
54 | [Market Barrow](market-barrow/) | A village lane with four numbered stalls (Mill, Harbour, Orchard, Forge), each with a chalk price board of four numbers, and a barrow that carries up to 10 goods (wool, salt, apples, iron): tap a stall, or press 1-4 or the arrow keys, to wheel there, which costs a day, and tap a good's buy or sell button to trade one; you start day 1 with 100 coins, prices swing between half and one and a half times the usual from a seed, a board shows the price you will meet on arrival at the other stalls, and travelling on day 10 ends the game, a win at 150 coins or more (goods left over count for nothing); the HUD shows the day, coins and barrow load, prices and loads are always written as numbers, and only the stall awnings move on their own (stopped under reduced motion) (forged by the crew on the engine and shell above, not by the original creators; rules in `market-barrow/barrow.js`) | Tap a stall, then buy or sell; 1-4 or Left and Right to travel |
5455 | [Sandcastle Tide](sandcastle/) | A square beach with a sandcastle on the far edge, rocks scattered over the sand and the sea along the near edge: tap a sand square to pat down a wall (or move a cursor with the arrow keys and press Space), four walls before each tide, then tap tide (or press Enter) and the water floods every square it can reach from the sea, a little further each time, never through a wall or a rock, and washes away half the walls it touches; keep the castle dry through five tides, the HUD showing the tide, the walls left and the dry squares; input is ignored while the water spreads, the surf line ripples (stopped under reduced motion), and sand, water, walls and rocks differ by texture as well as colour (forged by the crew on the engine and shell above, not by the original creators; rules in `sandcastle/tide.js`) | Tap a sand square, then tide; arrows and Space to build, Enter for the tide |
5556 | [Lock Keeper](lock-keeper/) | A flight of three canal locks climbing left to right, red narrowboats waiting at the bottom to go up and blue ones at the top to come down, in a seeded order (three rounds shipped, each with a par): tap a paddle or gate to work it and a boat to move it into or out of its lock, or Left and Right to pick a lock and 1 to 5 for its top paddle, bottom paddle, top gate, bottom gate and a boat; a gate opens only on level water, a paddle fills or empties the lock but not while the far gate is open, two open paddles flood the lock and lose the round, a refusal says why, and the end shows operations against par (forged by the crew on the engine and shell above, not by the original creators; rules in `lock-keeper/lock.js`) | Tap; Left and Right, 1 to 5 |
5657 | [Allotment](allotment/) | A five by five garden of raised beds with a bench holding the next seed packet: tap a bed to plant the packet there (or arrow keys to move and Space to plant); twelve packets in a season and every crop scores 1 plus its own rule for each touching bed (up, down, left, right): beans +3 per sweetcorn, sweetcorn -1 per sweetcorn, carrots -2 per onion, onion +2 per lettuce, lettuce +2 per carrots; 28 points by the last packet wins, against the best layout the rules could find (a seeded hand of eight seasons; forged by the crew on the engine and shell above, not by the original creators; rules in `allotment/plot.js`) | Tap a bed; arrows + Space |
@@ -79,7 +80,7 @@ On the forge, `forge.json` runs `bun serve.mjs` with health check `/`. State is
7980 Every page carries Open Graph and Twitter tags (between `og:begin` and `og:end`), and `og/<id>.png` is a 1200x630 card: the game's own opening frame, scaled 2x on white; `og/home.png` is a grid of all of them. Because the games are static, `bun scripts/og.mjs` makes them without a browser: it runs each page's scripts in a `vm` against a stub DOM, captures the canvas pixels and writes the PNG (zlib only, no dependency) and the tags. Run it after adding a game or changing a scene; `serve.test.mjs` fails when a card or its tags are missing or stale. Scenes are rendered with a seeded `Math.random`, so the cards are byte-for-byte reproducible. Absolute URLs use `ORIGIN` at the top of the script (the forge production site), so change it there if the site moves.
8081
8182 ## Add a game
82 Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry as a card with its `kind`, `input` and `accent`, searchable and filterable by kind (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too, with the same `data-kind`, `data-input`, `--accent` and tags line). Then run `bun scripts/og.mjs` to make its share card and tags. The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer, Domino Run, Campfire, Beekeeper, Bread Oven, Ice Fishing, Tightrope, Tram Line, Archery, Bell Tower, Espresso Bar, Goalkeeper, Wood Split, Signal Box, Soapbox Derby, Sheepdog, Firefly Jar, Hot Air Balloon, Cloakroom, Go-Kart Fete, Empire Age, Egg Basket, Dinghy Race, Coconut Shy, Bowls Green, Seed Packets, Hoopla Stall, Lock Keeper, Ferryman, Tower Duel, Sandcastle Tide, Hedge Maze and Allotment play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`.
83 Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules })`, set `window.PP_SCENE`, load `../engine.js`, then add the game to `GAMES` in `shell.js` with a one-line `blurb`; the home page lists every `GAMES` entry as a card with its `kind`, `input` and `accent`, searchable and filterable by kind (a static fallback list for no-JS is kept in sync by `serve.test.mjs`, so add the matching `<li>` to `index.html` too, with the same `data-kind`, `data-input`, `--accent` and tags line). Then run `bun scripts/og.mjs` to make its share card and tags. The page needs a `#mute` button. Put its background track at `<id>/<id>.mp3`, or set `music: false` on its `GAMES` entry when it has none (Stone Skip, Kite Hill, Paper Route, Harbour Crane, Pizza Toss, Sled Run, Pottery Wheel, Row Home, Orchard, Lighthouse, Market Scale, Window Washer, Domino Run, Campfire, Beekeeper, Bread Oven, Ice Fishing, Tightrope, Tram Line, Archery, Bell Tower, Espresso Bar, Goalkeeper, Wood Split, Signal Box, Soapbox Derby, Sheepdog, Firefly Jar, Hot Air Balloon, Cloakroom, Go-Kart Fete, Empire Age, Egg Basket, Dinghy Race, Coconut Shy, Bowls Green, Seed Packets, Hoopla Stall, Lock Keeper, Ferryman, Tower Duel, Sandcastle Tide, Hedge Maze, Allotment and Market Barrow play on their own sound effects). Rules that need testing go in a plain script with a `.test.mjs` beside it, as in `kite-hill/model.js`.
8384
8485 - `town.js` is the town's layout, pure data with no drawing: `window.PixelTown.layout(GAMES)` gives one isometric building per game (plot, screen position under the fixed 30-degree camera, accent, id) with trees in the spare plots, and `pick(town, x, y, filter)` gives the id of the front-most building under a screen point, or null. Nothing loads it yet; the drawing and the page are the second half of #99.
8586 - `shell.js` provides the game menu, the Rules popup, the credits and the background music. The menu lists the games grouped under their kind (the not-yet-made ones last, under Soon) and scrolls within the screen; type in its find box to narrow it by a word of the title, kind, input or blurb (keys typed there never reach the game), and press Escape to close it.
@@ -96,7 +97,7 @@ Create `<id>/index.html`, load `../shell.js`, call `PixelPlays.mount({ id, rules
9697 - Depth-buffer edges: darker where an object sits in front, a warm rim on upper-left edges.
9798 - Large flat surfaces use closely spaced tones; wide steps make the dither read as a checkerboard.
9899 - Characters stay sharp: flat bands with no dither, a dark silhouette on their own pixels, patterns at least 3px wide.
99 - Ambient motion only where the scene names it: grass and leaves sway in whole pixels at 8 fps, Tram Line's waiting passengers shift their weight, Espresso Bar's machine steam and awning fringe move, Sheepdog's crow on the wall shifts and dips its head, Hot Air Balloon's windsock and cloud wisps drift, Cloakroom's coats sway and the light under its door moves, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips, and Hoopla Stall's bunting flutters (the tossed ring is play, and still moves), and Lock Keeper's water surface ripples (the boats, gates and rising water are play, and still move), and Ferryman's river ripples (the ferry and its passengers are play, and still move), and Tower Duel's river ripples shift and the king towers' pennants stir (the troops and the fireball are play, and still move), and Hedge Maze's fountain splashes (the walker is play, and still moves), and Allotment's planted crops sway (the planting is play); all of it stops under `prefers-reduced-motion`.
100 - Ambient motion only where the scene names it: grass and leaves sway in whole pixels at 8 fps, Tram Line's waiting passengers shift their weight, Espresso Bar's machine steam and awning fringe move, Sheepdog's crow on the wall shifts and dips its head, Hot Air Balloon's windsock and cloud wisps drift, Cloakroom's coats sway and the light under its door moves, Go-Kart Fete's chequered flags flutter and its spectators wave, Egg Basket's hens peck and the straw in its basket stirs (its rolling eggs are play, not ambience, and still move), and Dinghy Race's water ripples come and go and its start-line flags flutter (the boats are play, and still sail), and Coconut Shy's bunting flutters and its stallholder shifts and waves (the thrown ball and wobbling coconuts are play, and still move), and Bowls Green's hedge leaves stir and a cloud shadow drifts across its green (the rolling woods are play, and still move), and Seed Packets' wall clock ticks its second hand and its watering can drips, and Hoopla Stall's bunting flutters (the tossed ring is play, and still moves), and Lock Keeper's water surface ripples (the boats, gates and rising water are play, and still move), and Ferryman's river ripples (the ferry and its passengers are play, and still move), and Tower Duel's river ripples shift and the king towers' pennants stir (the troops and the fireball are play, and still move), and Hedge Maze's fountain splashes (the walker is play, and still moves), and Allotment's planted crops sway (the planting is play) and Market Barrow's stall awnings flutter (the barrow is play, and still moves); all of it stops under `prefers-reduced-motion`.
100101
101102 ## Empire Age
102103
index.html +1
@@ -105,6 +105,7 @@ footer a::after { content: none; }
105105 <li data-kind="Racing" data-input="Drag" style="--accent:#2e8a7a"><a href="dinghy-race/">Dinghy Race</a><span>Drag to trim the sail to the wind and round three buoys ahead of the fleet</span><span>Game forged by the crew</span><span class="tags">Racing · Drag</span></li>
106106 <li data-kind="Memory" data-input="Tap" style="--accent:#7d9a4a"><a href="seed-packets/">Seed Packets</a><span>Tap to turn over seed packets and match every pair before the gardener comes back</span><span>Game forged by the crew</span><span class="tags">Memory · Tap</span></li>
107107 <li data-kind="Strategy" data-input="Tap" style="--accent:#4f7f6a"><a href="ferryman/">Ferryman</a><span>Row the fox, the goose and the grain across without leaving the wrong pair alone</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
108 <li data-kind="Strategy" data-input="Tap" style="--accent:#b5733a"><a href="market-barrow/">Market Barrow</a><span>Buy cheap and sell dear between the village stalls for ten days</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
108109 <li data-kind="Strategy" data-input="Tap" style="--accent:#d8b25a"><a href="sandcastle/">Sandcastle Tide</a><span>Pat down sand walls between tides and keep the castle dry through five high waters</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
109110 <li data-kind="Strategy" data-input="Tap" style="--accent:#5a6e8a"><a href="lock-keeper/">Lock Keeper</a><span>Work the paddles and gates to bring every narrowboat through the flight of locks</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
110111 <li data-kind="Strategy" data-input="Tap" style="--accent:#7a8f3a"><a href="allotment/">Allotment</a><span>Plant a season of crops where each one scores by its neighbours</span><span>Game forged by the crew</span><span class="tags">Strategy · Tap</span></li>
market-barrow/index.html added +413
@@ -0,0 +1,413 @@
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
6 <title>Market Barrow</title>
7 <!-- og:begin -->
8 <meta name="description" content="Buy cheap and sell dear between the village stalls for ten days">
9 <link rel="canonical" href="https://pixel-plays--forge-trevato-apps.open-platform.sh/market-barrow/">
10 <meta property="og:type" content="website">
11 <meta property="og:site_name" content="Pixel Plays">
12 <meta property="og:title" content="Market Barrow">
13 <meta property="og:description" content="Buy cheap and sell dear between the village stalls for ten days">
14 <meta property="og:url" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/market-barrow/">
15 <meta property="og:image" content="https://pixel-plays--forge-trevato-apps.open-platform.sh/og/market-barrow.png">
16 <meta property="og:image:type" content="image/png">
17 <meta property="og:image:width" content="1200">
18 <meta property="og:image:height" content="630">
19 <meta property="og:image:alt" content="Market Barrow: the opening scene of the game">
20 <meta name="twitter:card" content="summary_large_image">
21 <!-- og:end -->
22 <style>
23 :root { --ink: #1c1b19; --muted: #6b675f; --paper: #fff; --accent: #b5733a; }
outdated

--muted #8b877f on white is ~3.5:1; it styles the status line with the refusal text. Use something near #6b675f.

outdated

--muted is still #8b877f, about 3.5:1 on white. Use something near #6b675f.

24 * { box-sizing: border-box; }
25 html, body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
26 html, body { height: 100%; margin: 0; background: var(--paper); color: var(--ink); }
27 body { font: 13px/1.35 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace; overflow: hidden; }
28 #stage { position: fixed; inset: 0 0 136px 0; display: grid; place-items: center; }
29 canvas { display: block; image-rendering: pixelated; touch-action: none; cursor: pointer; outline: none; }

outline:none on the focusable canvas removes the only keyboard focus indicator; add canvas:focus-visible with a visible outline.

outline:none is still here with no canvas:focus-visible rule. Add a visible outline.

30 canvas:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
31 .hud { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); display: flex; justify-content: space-between; gap: 16px; pointer-events: none; }
32 #scores { position: fixed; top: max(14px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); display: grid; gap: 2px; pointer-events: none; }
33 #bottom { bottom: max(14px, env(safe-area-inset-bottom)); align-items: flex-end; }
outdated

Four columns at 360px are ~80px wide; each holds two 44px+ buttons (94px). Use grid-template-columns: repeat(2,1fr) below ~480px, or stack buy over sell.

outdated

Still four columns at 360px. Use repeat(2,1fr) below ~480px, or stack buy over sell.

34 #trade { position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); bottom: calc(max(14px, env(safe-area-inset-bottom)) + 30px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
35 .good { display: grid; justify-items: center; gap: 3px; min-width: 0; }
36 .good > span { color: var(--muted); white-space: nowrap; }
37 .good b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
38 .btns { display: flex; gap: 6px; }
39 .row { display: flex; align-items: center; gap: 8px; color: #8a5a28; }
40 .row b { font-size: 16px; font-weight: 600; min-width: 1ch; font-variant-numeric: tabular-nums; }
41 .row span { color: var(--muted); }
42 #status { color: var(--muted); min-height: 1.35em; }
43 button { pointer-events: auto; font: inherit; color: var(--muted); background: none; border: 0; padding: 10px; margin: -10px; cursor: pointer; }
outdated

Height ends up ~32px; set min-height:44px for thumbs.

outdated

Add min-height:44px on button.act.

44 button.act { color: var(--ink); border: 1px solid var(--muted); border-radius: 4px; padding: 7px 10px; margin: 0; min-width: 44px; min-height: 44px; }
45 button:hover, button:focus-visible { color: var(--ink); }
46 /* a phone: four columns of about 76 px, so each good stacks buy over sell at full column width */
47 @media (max-width: 479px) {
48 #stage { bottom: 186px; }
49 .btns { flex-direction: column; align-self: stretch; }
50 .btns button.act { width: 100%; }
51 }
52 button.act:hover, button.act:focus-visible { border-color: var(--ink); }
53 </style>
54 </head>
55 <body>
56 <div id="stage"><canvas id="c" tabindex="0" aria-label="A village lane with four market stalls in a row, numbered 1 to 4 (Mill, Harbour, Orchard, Forge), each with a price board of four numbers, and a barrow standing at one stall carrying wool, salt, apples and iron. Tap a stall, or press 1 to 4, to travel there, which costs a day. Use the buy and sell buttons under the lane to trade one good at a time. Buy where a good is cheap and sell where it is dear, and reach 150 coins by day 10."></canvas></div>
57 <div id="scores">
58 <div class="row"><b id="day">-</b><span>day</span></div>
59 <div class="row"><b id="coins">-</b><span>coins</span></div>
60 <div class="row"><b id="load">-</b><span>in the barrow</span></div>
61 </div>
62 <div id="trade">
63 <div class="good"><span>wool <b id="p-wool">-</b></span><span>carry <b id="c-wool">0</b></span><div class="btns"><button class="act" id="buy-wool" type="button" aria-label="buy wool">buy</button><button class="act" id="sell-wool" type="button" aria-label="sell wool">sell</button></div></div>
64 <div class="good"><span>salt <b id="p-salt">-</b></span><span>carry <b id="c-salt">0</b></span><div class="btns"><button class="act" id="buy-salt" type="button" aria-label="buy salt">buy</button><button class="act" id="sell-salt" type="button" aria-label="sell salt">sell</button></div></div>
65 <div class="good"><span>apples <b id="p-apples">-</b></span><span>carry <b id="c-apples">0</b></span><div class="btns"><button class="act" id="buy-apples" type="button" aria-label="buy apples">buy</button><button class="act" id="sell-apples" type="button" aria-label="sell apples">sell</button></div></div>
66 <div class="good"><span>iron <b id="p-iron">-</b></span><span>carry <b id="c-iron">0</b></span><div class="btns"><button class="act" id="buy-iron" type="button" aria-label="buy iron">buy</button><button class="act" id="sell-iron" type="button" aria-label="sell iron">sell</button></div></div>
67 </div>
68 <div class="hud" id="bottom">
69 <div id="status" role="status" aria-live="polite"></div>
70 <button id="mute" type="button" aria-pressed="false">sound on</button>
71 </div>
72 <script src="../shell.js"></script>
73 <script>
74 PixelPlays.mount({
75 id: 'market-barrow',
76 rules: [
77 'Tap a stall, or press 1 to 4, to travel there: every trip costs a day.',
78 'Tap buy or sell under the lane to trade one good; the barrow holds 10.',
79 'A board shows the price you will meet on arrival, so plan the next stall.',
80 'Reach 150 coins by day 10: goods left in the barrow count for nothing.',
81 ],
82 });
83 </script>
84 <script>window.PP_SCENE = { originY: 14, shadowX: 1.3, shadowY: -.12 };</script>
85 <script src="../engine.js"></script>
86 <script src="barrow.js"></script>
87 <script>
88 'use strict';
89
90 const DIRT = [196, 168, 124], VERGE = [112, 150, 82], WOOD = [150, 108, 70], WOOD_DARK = [104, 74, 50], SLATE = [44, 52, 56], FRAME = [196, 160, 110];
91 const CREAM = [244, 236, 214];
92 const GOOD_COLOUR = { wool: [238, 234, 222], salt: [160, 190, 236], apples: [200, 54, 46], iron: [92, 100, 116] };
93 const GOOD_LETTER = { wool: 'W', salt: 'S', apples: 'A', iron: 'I' };
94 const AWNING = [[198, 118, 56], [60, 112, 164], [98, 152, 72], [172, 62, 52]];
95 const STALL_U = [-12, -4, 4, 12], STALL_V = -3.5, STALL_HALF_U = 3.2, STALL_HALF_V = 1.3, FRONT_V = STALL_V + STALL_HALF_V;
96 const LANE_HALF_U = 16.5, LANE_V0 = -6.8, LANE_V1 = 7.2, BARROW_V = 3.6, SPEED = 18;
97 const AWNING_FRONT_V = FRONT_V + .6, AWNING_LOW = 4.25, AWNING_HIGH = 4.75;
98 const BEST_KEY = 'pixel-plays-market-barrow-best';
99 const INK_PIX = rgb(28, 27, 25), WHITE_PIX = rgb(255, 255, 255), CHALK = rgb(246, 244, 232), HIGH_PIX = rgb(255, 196, 96);
100 // 3x5 pixel glyphs, row by row: the price boards and counter numbers are always written out
101 const GLYPH = {
102 0: '111101101101111', 1: '010110010010111', 2: '111001111100111', 3: '111001111001111', 4: '101101111001001',
103 5: '111100111001111', 6: '111100111101111', 7: '111001001001001', 8: '111101111101111', 9: '111101111001111',
104 W: '101101101111101', S: '011100010001110', A: '010101111101101', I: '111010010010111',
105 };
106
107 const world = (u, v, z) => [(u + v) / R2, (v - u) / R2, z];
108 const lastBest = (() => { try { const n = parseInt(localStorage.getItem(BEST_KEY), 10); return Number.isInteger(n) && n > 0 ? n : 0; } catch (e) { return 0; } })();
109
110 /* ---------- state ---------- */
111 let seed = Math.floor(Date.now() / 1000), R = MarketBarrow.start(seed, lastBest);
112 const G = { time: 0, noteUntil: 0, barrowU: STALL_U[0] };
113 const nodes = {};
114 for (const k of ['day', 'coins', 'load', 'status']) nodes[k] = document.getElementById(k);
115 for (const g of MarketBarrow.GOODS) { nodes['p-' + g] = document.getElementById('p-' + g); nodes['c-' + g] = document.getElementById('c-' + g); }
116 const shown = {};
117 function setText(key, text) {
118 if (shown[key] === text) return;
119 shown[key] = text;
120 nodes[key].textContent = text;
121 }
122 const stallIndex = () => MarketBarrow.STALLS.indexOf(R.stall);
123 const loadOf = () => MarketBarrow.load(R);
124 function renderHud() {
125 setText('day', `${R.day} of ${MarketBarrow.DAYS}`);
126 setText('coins', String(R.coins));
127 setText('load', `${loadOf()} of ${R.capacity}`);
128 for (const g of MarketBarrow.GOODS) { setText('p-' + g, String(R.prices[g])); setText('c-' + g, String(R.cargo[g])); }
129 }
130 function note(text) { setText('status', text); G.noteUntil = G.time + 2.5; }
131
132 /* ---------- painting ---------- */
133 function put(ramp, u, v, z, tone) {
134 const p = project((u + v) / R2, (v - u) / R2, z), ix = p.sx | 0, iy = p.sy | 0;
135 if (ix < 0 || iy < 0 || ix >= W || iy >= H) return;
136 const i = iy * W + ix;
137 if (p.d <= zb[i]) return;
138 zb[i] = p.d;
139 pix[i] = ramp[clamp(Math.floor(tone + (bayerAt(ix, iy) - .5) * .5), 0, 4)];
140 }
141 function top(ramp, u0, u1, v0, v1, z, tone, step = .08) {
142 for (let u = u0; u <= u1; u += step) for (let v = v0; v <= v1; v += step) put(ramp, u, v, typeof z === 'function' ? z(v) : z, typeof tone === 'function' ? tone(u, v) : tone);
143 }
144 function front(ramp, u0, u1, v, z0, z1, tone, step = .08) {
145 for (let u = u0; u <= u1; u += step) for (let z = z0; z <= z1; z += step) put(ramp, u, v, z, typeof tone === 'function' ? tone(u, z) : tone);
146 }
147 function side(ramp, u, v0, v1, z0, z1, tone, step = .08) {
148 for (let v = v0; v <= v1; v += step) for (let z = z0; z <= z1; z += step) put(ramp, u, v, z, typeof tone === 'function' ? tone(v, z) : tone);
149 }
150 // a solid block: lit top, mid front face, dark right face
151 function block(ramp, u0, u1, v0, v1, z0, z1, grain = 0, step = .08) {
152 const g = (a, b) => (grain ? (noise(a * 3, b * 3) - .5) * grain : 0);
153 top(ramp, u0, u1, v0, v1, z1, (u, v) => 3.3 + g(u, v), step);
154 front(ramp, u0, u1, v1, z0, z1, (u, z) => 2.3 + g(u, z), step);
155 side(ramp, u1, v0, v1, z0, z1, (v, z) => 1.2 + g(v, z), step);
156 }
157 const stripe = (u, w) => Math.floor((u + 100) / w) & 1;
158
159 const dirtRamp = rampOf(DIRT), vergeRamp = rampOf(VERGE), woodRamp = rampOf(WOOD), darkRamp = rampOf(WOOD_DARK), slateRamp = rampOf(SLATE), frameRamp = rampOf(FRAME), creamRamp = rampOf(CREAM);
160 function groundColor(x, y, ix, iy) {
161 const u = (x - y) / R2, v = (x + y) / R2;
162 if (Math.max(Math.abs(u) - LANE_HALF_U, v - LANE_V1, LANE_V0 - v) > -hash(ix, iy) * 1.2) return 0; // a ragged edge into the white
163 const t = .96 + (hash(ix, iy) - .5) * .1 + (noise(u * .6, v * .9) - .5) * .1;
164 if (v < -5.3 || v > 6.3) return rgb(VERGE[0] * t, VERGE[1] * t, VERGE[2] * t);
165 const cobble = hash(Math.floor(u * 1.6), Math.floor(v * 1.6)) > .86 ? .88 : 1; // a few darker cobbles in the lane
166 return rgb(DIRT[0] * t * cobble, DIRT[1] * t * cobble, DIRT[2] * t * cobble);
167 }
168 function bakeStall(k) {
169 const su = STALL_U[k], accent = AWNING[k], name = MarketBarrow.STALLS[k], good = MarketBarrow.GOODS[k];
170 const u0 = su - STALL_HALF_U, u1 = su + STALL_HALF_U, v0 = STALL_V - STALL_HALF_V;
171 block(woodRamp, u0, u1, v0, FRONT_V, 0, 1.5, .6);
172 for (const pu of [u0 + .15, u1 - .15]) for (const pv of [v0 + .15, FRONT_V - .15]) { // four posts up to the awning
173 capsule(world(pu, pv, 0), world(pu, pv, AWNING_HIGH), .13, .13, () => WOOD_DARK, 'solid');
174 }
175 // the price board, a chalk slate in a frame, hung under the awning on the counter's front plane
176 top(frameRamp, su - 3.05, su + 3.05, FRONT_V, FRONT_V, 4.45, 3.4);
177 front(frameRamp, su - 3.05, su + 3.05, FRONT_V + .01, 1.5, 4.45, 3);
178 front(slateRamp, su - 2.95, su + 2.95, FRONT_V + .02, 1.62, 4.35, 1.8);
179 // what the stall sells, in a small pile on the counter
180 const c = rampOf(GOOD_COLOUR[good]);
181 block(c, su - 1.2, su - .2, v0 + .3, v0 + 1.2, 1.5, 2.2, .8, .06);
182 block(c, su + .2, su + 1.1, v0 + .5, v0 + 1.3, 1.5, 2.0, .8, .06);
183 // the awning: a sloped striped roof, lower at the front
184 const aRamp = rampOf(accent), slope = v => AWNING_LOW + (AWNING_HIGH - AWNING_LOW) * (AWNING_FRONT_V - v) / (AWNING_FRONT_V - (v0 - .2));
185 top(aRamp, u0 - .3, u1 + .3, v0 - .2, AWNING_FRONT_V, slope, u => (stripe(u - su, .85) ? 3.6 : 2.4), .06);
186 top(creamRamp, u0 - .3, u0 - .25, v0 - .2, AWNING_FRONT_V, slope, 3, .05);
187 for (let q = -3; q <= 3; q++) castShadow(...world(su + q * .9, STALL_V, 0).slice(0, 2), AWNING_HIGH, .8, 1, 0);
188 return name;
189 }
190 function bake() {
191 ground.fill(0); shadowMask.fill(0); staticShadow.fill(0); kinds.fill(0);
192 tufts.length = 0; leaves.length = 0;
193 zb.fill(-1e9);
194 pix.fill(rgb(255, 255, 255));
195 for (let iy = 0; iy < H; iy++) for (let ix = 0; ix < W; ix++) {
196 const g = unproject(ix + .5, iy + .5), i = iy * W + ix, c = groundColor(g.x, g.y, ix, iy);
197 if (!c) continue;
198 pix[i] = c; ground[i] = 1;
199 zb[i] = (g.x + g.y) / R2 * COS;
200 }
201 groundZ.set(zb);
202 for (let k = 0; k < STALL_U.length; k++) bakeStall(k);
203 bakeOcclusion();
204 applyShadows(groundZ);
205 bakedPix.set(pix);
206 bakedZ.set(zb);
207 }
208
209 /* ---------- text on the canvas, in whole pixels ---------- */
210 function glyph(sx, sy, ch, pixel, scale = 2) {
211 const g = GLYPH[ch];
212 if (!g) return;
213 for (let k = 0; k < 15; k++) if (g[k] === '1') for (let dy = 0; dy < scale; dy++) for (let dx = 0; dx < scale; dx++) {
214 const x = sx + (k % 3) * scale + dx, y = sy + Math.floor(k / 3) * scale + dy;
215 if (x >= 0 && y >= 0 && x < W && y < H) pix[y * W + x] = pixel;
216 }
217 }
218 const advance = scale => 4 * scale;
219 function write(sx, sy, str, pixel, scale = 2) {
220 [...str].forEach((ch, n) => glyph(sx + n * advance(scale), sy, ch, pixel, scale));
221 }
222 function outlined(sx, sy, str, pixel) {
223 for (const [dx, dy] of [[-1, 0], [1, 0], [0, -1], [0, 1], [-1, -1], [1, 1], [-1, 1], [1, -1]]) write(sx + dx, sy + dy, str, INK_PIX);
224 write(sx, sy, str, pixel);
225 }
226 // the numbers each stall shows: the current stall's own board, and the price you would meet on arrival at the others
227 const boardPrices = k => (k === stallIndex() ? R.prices : MarketBarrow.prices(R.seed, MarketBarrow.STALLS[k], Math.min(R.day + 1, MarketBarrow.DAYS)));
228 function drawBoards() {
229 for (let k = 0; k < STALL_U.length; k++) {
230 const p = project(...world(STALL_U[k] - 2.95, FRONT_V, 4.35)), x0 = Math.round(p.sx) + 5, y0 = Math.round(p.sy) + 1, prices = boardPrices(k);
231 MarketBarrow.GOODS.forEach((good, n) => {
232 const x = x0 + (n % 2) * 29, y = y0 + (n >> 1) * 11, str = String(prices[good]).padStart(2, ' ');
233 write(x, y, GOOD_LETTER[good], rgb(...GOOD_COLOUR[good]), 2);
234 write(x + 8, y, str, k === stallIndex() ? rgb(255, 220, 90) : CHALK, 2);
235 });
236 const c = project(...world(STALL_U[k], FRONT_V, 1.4)); // the stall's number on its counter
237 outlined(Math.round(c.sx) - 3, Math.round(c.sy) - 1, String(k + 1), WHITE_PIX);
238 }
239 }
240
241 /* ---------- the barrow, drawn each frame ---------- */
242 function drawBarrow() {
243 const u = G.barrowU, v = BARROW_V, bed = rampOf(WOOD), dark = rampOf(WOOD_DARK);
244 block(bed, u - 1.7, u + 1.7, v - 1.2, v + 1.2, .6, 1.1, .6, .06);
245 for (const dv of [-1.1, 1.1]) capsule(world(u - 1.7, v + dv, 1), world(u - 3.2, v + dv, 1.8), .1, .1, () => WOOD_DARK, 'solid'); // handles
246 sphere(...world(u + 1.7, v, .6), .6, [58, 52, 48], 'solid'); // the wheel
247 const flat = [];
248 MarketBarrow.GOODS.forEach(g => { for (let n = 0; n < R.cargo[g]; n++) flat.push(g); });
249 flat.forEach((g, n) => { // each carried unit is a small crate: two layers of five
250 const col = n % 5, layer = Math.floor(n / 5), cu = u - 1.2 + col * .6, cv = v - .35, lz = 1.1;
251 block(rampOf(GOOD_COLOUR[g]), cu - .25, cu + .25, cv - .3 + (layer ? .1 : 0), cv + .3 + (layer ? .1 : 0), lz, lz + .45, .6, .05);
252 });
253 castShadow(...world(u, v, 0).slice(0, 2), 1.4, 2.1, 1, 0);
254 }
255 function draw() {
256 pix.set(bakedPix);
257 zb.set(bakedZ);
258 drawBarrow();
259 drawAwnings();
260 applyShadows(groundZ);
261 shadeEdges();
262 drawBoards();
263 const p = project(...world(G.barrowU, BARROW_V, 2.3)); // the load, as a number, above the barrow
264 outlined(Math.round(p.sx) - 3, Math.round(p.sy) - 4, String(loadOf()), WHITE_PIX);
265 if (R.status === 'over') { // a red bar over the lane's top edge when it ends
266 const c = R.result === 'won' ? HIGH_PIX : rgb(214, 48, 40);
267 for (let x = 90; x < 270; x++) for (const y of [20, 21]) pix[y * W + x] = c;
268 }
269 ctx.putImageData(image, 0, 0);
270 }
271 // the awning valances, the one thing that moves on its own: scallops that shift a pixel at 8 fps, still under reduced motion
272 function drawAwnings() {
273 const beat = STILL ? 0 : Math.floor(G.time * 8);
274 for (let k = 0; k < STALL_U.length; k++) {
275 const su = STALL_U[k], shift = STILL ? 0 : [0, .1, .2, .1][(beat + k) & 3], ramp = rampOf(AWNING[k]);
276 for (let u = su - STALL_HALF_U - .3; u <= su + STALL_HALF_U + .3; u += .05) {
277 const edge = AWNING_LOW - .45 + .22 * Math.abs(Math.sin((u + shift) * Math.PI / .85)), tone = stripe(u + shift - su, .85) ? 3.2 : 2;
278 for (let z = edge; z <= AWNING_LOW; z += .05) put(ramp, u, AWNING_FRONT_V, z, tone);
279 }
280 }
281 }
282
283 /* ---------- game ---------- */
284 const HINT = 'tap a stall to travel there, then buy or sell';
285 const REFUSALS = {
286 'already-here': () => `you are at the ${R.stall} stall already`,
287 'barrow-full': 'the barrow is full', 'too-poor': 'not enough coins', 'not-carried': 'none of that in the barrow',
288 'bad-quantity': 'trade one at a time', 'unknown-good': 'no such good', 'unknown-stall': 'no such stall', 'game-over': 'the ten days are over',
289 };
290 // what the status line says for a refused move: every code barrow.js can return has words here
291 const refusal = why => { const say = REFUSALS[why]; return typeof say === 'function' ? say() : say || 'that cannot be done'; };
292 function line() {
293 if (R.status === 'over') return `${R.line} · best ${R.best} · tap or press a key to play again`;
294 return R.day === MarketBarrow.DAYS ? `${R.line} · last day: travelling ends the game` : R.line;
295 }
296 function restart() {
297 ensureAudio();
298 seed++;
299 R = MarketBarrow.start(seed, R.best);
300 G.barrowU = STALL_U[0];
301 renderHud(); note(HINT);
302 }
303 function afterMove(out, tone) {
304 if (!out.ok) { sound(140, .15, 'sawtooth'); note(refusal(out.why)); return false; }
305 R = out.state;
306 sound(tone, .08, 'triangle');
307 renderHud();
308 return true;
309 }
310 function trade(kind, good) {
311 ensureAudio();
312 if (R.status === 'over') { restart(); return; }
313 if (afterMove(MarketBarrow[kind](R, good, 1), kind === 'buy' ? 360 : 520)) note(R.line);
314 }
315 function goTo(k) {
316 ensureAudio();
317 if (R.status === 'over') { restart(); return; }
318 const name = MarketBarrow.STALLS[k];
319 if (!name || !afterMove(MarketBarrow.travel(R, name), 260)) return;
320 if (R.status === 'over') {
321 try { localStorage.setItem(BEST_KEY, String(R.best)); } catch (err) { /* private window: keep it for this visit */ }
322 if (R.result === 'won') { sound(520, .3, 'sine'); sound(780, .5, 'sine', .15); } else sound(110, .6, 'sawtooth');
323 setText('status', line()); G.noteUntil = 0;
324 } else note(R.line);
325 }
326 function update(dt) {
327 G.time += dt;
328 const to = STALL_U[stallIndex()], step = SPEED * dt;
329 G.barrowU = Math.abs(to - G.barrowU) <= step ? to : G.barrowU + Math.sign(to - G.barrowU) * step;
330 if (R.status === 'over' || G.time >= G.noteUntil) setText('status', line());
331 }
332
333 /* ---------- input ---------- */
334 // the stall under a point on the canvas, or -1: its column of the lane, from the awning down to the lane's front edge
335 function stallAt(px, py) {
336 const g = unproject(px, py), u = (g.x - g.y) / R2;
337 if (py < 70 || py > 205) return -1;
338 const k = Math.floor((u + 16) / 8);
339 return k >= 0 && k < STALL_U.length ? k : -1;
340 }
341 const stallCentre = k => { const p = project(...world(STALL_U[k], FRONT_V, 2)); return [p.sx, p.sy]; };
342 canvas.addEventListener('pointerdown', e => {
343 canvas.focus({ preventScroll: true });
344 const r = canvas.getBoundingClientRect(), px = (e.clientX - r.left) / r.width * W, py = (e.clientY - r.top) / r.height * H;
345 if (R.status === 'over') { restart(); return; }
346 const k = stallAt(px, py);
347 if (k >= 0) goTo(k);
348 });
349 canvas.addEventListener('keydown', e => {
350 const n = parseInt(e.key, 10), pick = n >= 1 && n <= 4 && e.key.length === 1, step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0;
351 if (!pick && !step) return;
352 e.preventDefault();
353 if (e.repeat) return;
354 if (R.status === 'over') { restart(); return; }
355 const k = pick ? n - 1 : stallIndex() + step;
356 if (k >= 0 && k < STALL_U.length) goTo(k);
357 });
358 for (const g of MarketBarrow.GOODS) {
359 document.getElementById('buy-' + g).addEventListener('click', () => { canvas.focus({ preventScroll: true }); trade('buy', g); });
360 document.getElementById('sell-' + g).addEventListener('click', () => { canvas.focus({ preventScroll: true }); trade('sell', g); });
361 }
362
363 /* ---------- sound ---------- */
364 let audio = null, muted = false;
365 function ensureAudio() {
366 if (audio) { if (audio.state === 'suspended') audio.resume(); return; }
367 const AC = window.AudioContext || window.webkitAudioContext;
368 if (AC) audio = new AC();
369 }
370 function sound(freq, life, type, delay = 0) {
371 if (!audio || muted) return;
372 const now = audio.currentTime + delay, gain = audio.createGain(), osc = audio.createOscillator();
373 osc.type = type;
374 osc.frequency.setValueAtTime(freq, now);
375 gain.gain.setValueAtTime(.0001, now);
376 gain.gain.exponentialRampToValueAtTime(.07, now + .01);
377 gain.gain.exponentialRampToValueAtTime(.0005, now + life);
378 osc.connect(gain).connect(audio.destination);
379 osc.start(now); osc.stop(now + life + .02);
380 }
381 const muteButton = document.getElementById('mute');
382 muteButton.addEventListener('click', () => {
383 muted = !muted;
384 muteButton.textContent = muted ? 'sound off' : 'sound on';
385 muteButton.setAttribute('aria-pressed', String(muted));
386 });
387
388 /* ---------- fit and boot ---------- */
389 // the engine's fit leaves 40 px for the HUD; the trade row needs more, and more again on a phone where buy stacks over sell
390 const deckHeight = () => (innerWidth < 480 ? 186 : 136);
391 function fitLane() {
392 const dpr = window.devicePixelRatio || 1;
393 const scale = Math.max(1, Math.floor(Math.min(innerWidth / W, (innerHeight - deckHeight()) / H) * dpr)) / dpr;
394 canvas.style.width = W * scale + 'px';
395 canvas.style.height = H * scale + 'px';
396 }
397 addEventListener('resize', fitLane);
398 fitLane();
399 bake();
400 note(HINT);
401 renderHud();
402 canvas.focus({ preventScroll: true });
403 let last = performance.now();
404 function frame(now) {
405 update(Math.min(.04, (now - last) / 1000));
406 last = now;
407 draw();
408 requestAnimationFrame(frame);
409 }
410 requestAnimationFrame(frame);
411 </script>
412 </body>
413 </html>
market-barrow/page.test.mjs added +86
@@ -0,0 +1,86 @@
1 import { readFileSync } from 'node:fs';
2 import { test, expect } from 'bun:test';
3 import { boot } from '../playtest.mjs';
4
5 const state = g => g.read('R');
6 const html = readFileSync(new URL('./index.html', import.meta.url), 'utf8');
7 const rules = readFileSync(new URL('./barrow.js', import.meta.url), 'utf8');
8
9 // WCAG relative luminance and contrast of two #rrggbb colours
10 const lum = hex => {
11 const c = [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16) / 255).map(v => (v <= .03928 ? v / 12.92 : ((v + .055) / 1.055) ** 2.4));
12 return .2126 * c[0] + .7152 * c[1] + .0722 * c[2];
13 };
14 const contrast = (a, b) => { const [x, y] = [lum(a), lum(b)].sort((p, q) => q - p); return (x + .05) / (y + .05); };
15
16 test('every code barrow.js refuses with has words on the status line, never the raw code', () => {
17 const codes = [...new Set([...rules.matchAll(/reject\(state, '([a-z-]+)'\)/g)].map(m => m[1]))];
18 expect(codes.length).toBeGreaterThan(5);
19 const g = boot('market-barrow');
20 for (const why of codes) {
21 expect(g.read(`Object.hasOwn(REFUSALS, ${JSON.stringify(why)})`)).toBe(true);
22 const said = g.read(`refusal(${JSON.stringify(why)})`);
23 expect(said).not.toBe(why);
24 expect(said.length).toBeGreaterThan(5);
25 }
26 expect(g.errors).toEqual([]);
27 });
28
29 test('a refused travel shows its words: pressing the stall you stand at', () => {
30 const g = boot('market-barrow');
31 g.press('1', .2);
32 expect(String(g.el('status').textContent)).toBe(`you are at the ${state(g).stall} stall already`);
33 expect(state(g).day).toBe(1);
34 expect(g.errors).toEqual([]);
35 });
36
37 test('keys 1 to 4 and the arrows travel between stalls, a day each', () => {
38 const g = boot('market-barrow');
39 const stalls = g.read('MarketBarrow.STALLS');
40 g.press('3', .2);
41 expect(state(g).stall).toBe(stalls[2]);
42 expect(state(g).day).toBe(2);
43 g.press('ArrowRight', .2);
44 expect(state(g).stall).toBe(stalls[3]);
45 g.press('ArrowRight', .2); // no fifth stall: nothing happens
46 expect(state(g).stall).toBe(stalls[3]);
47 expect(state(g).day).toBe(3);
48 g.press('ArrowLeft', .2);
49 expect(state(g).stall).toBe(stalls[2]);
50 expect(String(g.el('day').textContent)).toBe('4 of 10');
51 expect(g.errors).toEqual([]);
52 });
53
54 test('the buy and sell buttons trade one unit, and the end restarts with the best kept', () => {
55 const g = boot('market-barrow');
56 const coins = state(g).coins, price = state(g).prices.wool;
57 g.el('buy-wool').fire('click');
58 expect(state(g).cargo.wool).toBe(1);
59 expect(state(g).coins).toBe(coins - price);
60 g.el('sell-wool').fire('click');
61 expect(state(g).cargo.wool).toBe(0);
62 g.el('sell-wool').fire('click');
63 expect(String(g.el('status').textContent)).toBe('none of that in the barrow');
64 for (let d = 0; d < 10 && state(g).status !== 'over'; d++) g.press(d % 2 ? '1' : '2', .2);
65 expect(state(g).status).toBe('over');
66 expect(String(g.el('status').textContent)).toMatch(/best \d+ · tap or press a key to play again/);
67 const best = state(g).best;
68 g.press('2', .2);
69 expect(state(g).status).toBe('playing');
70 expect(state(g).day).toBe(1);
71 expect(state(g).best).toBe(best);
72 expect(g.errors).toEqual([]);
73 });
74
75 test('on a phone the trade buttons are thumb-sized and buy stacks over sell', () => {
76 expect(html).toMatch(/button\.act \{[^}]*min-width: 44px;[^}]*min-height: 44px;/);
77 const phone = html.match(/@media \(max-width: 479px\) \{([\s\S]*?)\n \}/);
78 expect(phone).not.toBeNull();
79 expect(phone[1]).toMatch(/\.btns \{[^}]*flex-direction: column/);
80 });
81
82 test('muted text reads at 4.5:1 on the paper, and the canvas shows where focus is', () => {
83 const muted = html.match(/--muted: (#[0-9a-f]{6})/)[1], paper = html.match(/--paper: (#[0-9a-f]{3,6})/)[1];
84 expect(contrast(muted, paper.length === 4 ? '#ffffff' : paper)).toBeGreaterThanOrEqual(4.5);
85 expect(html).toMatch(/canvas:focus-visible \{ outline: 2px solid var\(--ink\)/);
86 });
og/home.png
Binary file not shown.
og/market-barrow.png added
Binary file not shown.
rounds.mjs +7
@@ -183,6 +183,13 @@ export const ROUNDS = {
183183 g.tap(...g.read('ferryAt()'));
184184 g.run(.3);
185185 } },
186 // sell what the barrow carries, buy one apple, then wheel to the next stall; the tenth trip ends the game
187 'market-barrow': { over: /Won with|Lost with/, outcome: /(Won|Lost) with \d+ coins/, beat: g => {
188 for (const good of g.read('MarketBarrow.GOODS')) if (g.read(`R.cargo.${good}`) > 0) g.el(`sell-${good}`).fire('click');
189 g.el('buy-apples').fire('click');
190 g.tap(...g.read(`stallCentre((MarketBarrow.STALLS.indexOf(R.stall) + 1) % MarketBarrow.STALLS.length)`));
191 g.run(.3);
192 } },
186193 // wall off the row above the sea, then call the tide with Enter; the flood plays out before the next beat
187194 'sandcastle': { over: /castle stayed dry|sea reached the castle/, outcome: /The (castle stayed dry through \d+ tides|sea reached the castle in tide \d+)/, beat: g => {
188195 if (g.read('busy()')) { g.run(.3); return; }
serve.test.mjs +7
@@ -472,6 +472,13 @@ test('Sandcastle Tide and its rules script are served without a track', async ()
472472 expect((await fetch(base + '/sandcastle/tide.js')).status).toBe(200);
473473 });
474474
475 test('Market Barrow and its rules script are served without a track', async () => {
476 const page = await fetch(base + '/market-barrow/');
477 expect(page.status).toBe(200);
478 expect(page.headers.get('content-type')).toBe('text/html; charset=utf-8');
479 expect((await fetch(base + '/market-barrow/barrow.js')).status).toBe(200);
480 });
481
475482 test('Seed Packets and its rules script are served without a track', async () => {
476483 const page = await fetch(base + '/seed-packets/');
477484 expect(page.status).toBe(200);
shell.js +1
@@ -45,6 +45,7 @@ window.PixelPlays = (() => {
4545 { id: 'dinghy-race', title: 'Dinghy Race', blurb: 'Drag to trim the sail to the wind and round three buoys ahead of the fleet', kind: 'Racing', input: 'Drag', accent: '#2e8a7a', music: false, forged: true },
4646 { id: 'seed-packets', title: 'Seed Packets', blurb: 'Tap to turn over seed packets and match every pair before the gardener comes back', kind: 'Memory', input: 'Tap', accent: '#7d9a4a', music: false, forged: true },
4747 { id: 'ferryman', title: 'Ferryman', blurb: 'Row the fox, the goose and the grain across without leaving the wrong pair alone', kind: 'Strategy', input: 'Tap', accent: '#4f7f6a', music: false, forged: true },
48 { id: 'market-barrow', title: 'Market Barrow', blurb: 'Buy cheap and sell dear between the village stalls for ten days', kind: 'Strategy', input: 'Tap', accent: '#b5733a', music: false, forged: true },
4849 { id: 'sandcastle', title: 'Sandcastle Tide', blurb: 'Pat down sand walls between tides and keep the castle dry through five high waters', kind: 'Strategy', input: 'Tap', accent: '#d8b25a', music: false, forged: true },
4950 { id: 'lock-keeper', title: 'Lock Keeper', blurb: 'Work the paddles and gates to bring every narrowboat through the flight of locks', kind: 'Strategy', input: 'Tap', accent: '#5a6e8a', music: false, forged: true },
5051 { id: 'allotment', title: 'Allotment', blurb: 'Plant a season of crops where each one scores by its neighbours', kind: 'Strategy', input: 'Tap', accent: '#7a8f3a', music: false, forged: true },

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs