Whack-a-mole grid game with scripted pops, bees, and scoring
Build a small arcade game for a gardening app. Gophers pop out of the holes in a 3 × 3 garden and the player taps them to chase them off before the round ends. Bees sometimes come out of a hole too, and tapping one costs points.
So the game is predictable (and testable), what pops up is scripted instead of random. The starter code includes the game data:
const HOLE_COUNT = 9;
const ROUND_TICKS = 10;
const TICK_MS = 1000;
const BEE_PENALTY = 2;
// What is out at each tick of a round. Hole indexes are 0-based. The script repeats.
const SPAWNS = [
[{ hole: 4, kind: 'gopher' }],
[{ hole: 0, kind: 'gopher' }, { hole: 8, kind: 'bee' }],
[{ hole: 2, kind: 'bee' }],
[{ hole: 6, kind: 'gopher' }, { hole: 1, kind: 'gopher' }],
[{ hole: 3, kind: 'gopher' }, { hole: 4, kind: 'bee' }],
];
HOLE_COUNT clickable holes in order (3 per row). Hole i of the data is shown to the user as Hole i + 1. Each hole has aria-label="Hole <N>, <state>", where state is empty, gopher or bee (for example aria-label="Hole 5, gopher").Score: N, Time left: N and Best: N. Before the first round they read Score: 0, Time left: 10 (ROUND_TICKS) and Best: 0.Start button begins a round. Before that, every hole is empty and clicking holes does nothing.ROUND_TICKS ticks of TICK_MS each.
SPAWNS[0] right away and Time left is ROUND_TICKS.TICK_MS, the tick number goes up by 1, Time left goes down by 1, and the holes show exactly SPAWNS[tick % SPAWNS.length]. Everything else is empty.BEE_PENALTY points, but the score never goes below 0.Start must not restart it. Disabling the button is the simplest way.ROUND_TICKS:
Time left shows 0 and every hole is empty.Time's up! You scored N.Best becomes the highest final score of any round so far.Play again. Clicking holes does nothing.ROUND_TICKS, the script starts again at SPAWNS[0], and the message is hidden. Best is kept.Click Start Hole 5 gopher Score 0, Time left 10
Click Hole 5 Hole 5 empty Score 1
After 1 tick Hole 1 gopher, Hole 9 bee Time left 9
Click Hole 9 bee: 1 - 2 = -1, so 0 Score 0
Click Hole 1 gopher Score 1
After 2 more ticks Hole 7 gopher, Hole 2 gopher Time left 7
...
After tick 10 all holes empty Time left 0
"Time's up! You scored 1." Best 1
SPAWNS[0] again: the script repeats.Time left reaches 0.The tests replace setTimeout/setInterval with a fake clock and move time forward by whole ticks, then click holes and read the screen like a user would. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
aria-label is Hole <N>, <state>, in DOM order.Score: N, Time left: N, Best: N and the round-over message appear as described.Start and Play again buttons work as described.Capitalization and extra spacing don’t matter.