UXInteract / task_041 /instruction.md
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
|
Raw History Blame Contribute Delete
3.92 kB

Build a Gold Miner mini-game

Create an offline index.html with a home menu and one playable canvas level.

Starting a game

On the home menu, let the player choose single-player or two-player mode and click a separate Start button. Selecting a mode leaves play inactive until Start is clicked. Before starting, the state may expose idle preview hooks, but neither key launches a hook. Start opens the same playable level with A's hook in single-player mode or both A's and B's hooks in two-player mode.

Mark the home menu with data-testid="mode-menu" and the Start control with data-testid="start-game". For a native select, use data-testid="game-mode" and option values single and double. For other controls, put data-testid="mode-single" and data-testid="mode-double" on the respective clickable choices.

Gameplay

  • Each player has a swinging surface hook. Press s for A or ArrowDown for B to launch that hook along its current angle. A miss at the edge returns along the same path without scoring.
  • The default field contains small and large gold, stones of at least two sizes, bombs, pigs and at least three diamonds. Weight and value vary with the size of gold and stones. Stones are heaviest; diamonds and pigs lightest. Diamonds are the most valuable objects at 800 points, and bombs are the least valuable at 2 points. Pigs are worth 3 points and move slowly back and forth horizontally. All other item values are strictly between 2 and 800 points.
  • A hook retrieves the object it hits. Heavier catches retract more slowly. Bombs explode visibly and retract quickly. Each completed catch removes the item and credits its value once. Put A's numeric score alone in #scoreA and show a visible “Victory” or “胜利” surprise upon reaching the default target of 800.

State interface

Expose window.gameTest with reset(config), step(milliseconds), dropClaw(player = 'A') and state(), driving the same simulation and rendering as the visible game.

  • reset accepts {mode?, targetScore?, items?}; mode: 'double' activates both hooks. A supplied targetScore replaces 800 for that round. Report it as target and set won and show the victory message when either player's score reaches or exceeds it. Items are {type,x,y,def?} in canvas pixels, with type diamond, pig, bomb, goldS, goldL or stone. In a single-player reset hook A points vertically down from horizontal coordinate 320.
  • step advances and renders the game in steps of about 16 ms. dropClaw performs the same action as the matching key.
  • state() returns {scores:{A,B},target,won,explosions,items:[{type,x,y,value,weight,grabbed}],hooks:[{player,state,len,holding,fastReturn}]}. Idle hooks are in 'swing', launched hooks in 'extend'. Length len is in pixels; holding is a type or null.

Acceptance Checklist

  • The home menu supports both modes. Selecting either mode leaves play inactive. Clicking Start enters the selected game, and the live keyboard inputs launch the corresponding hooks.
  • The default field contains every listed item type, including enough diamonds and differently sized stones. Diamonds and bombs set the upper and lower bounds for item values.
  • Both key controls launch their own hooks; a miss returns to idle within four seconds, and a pig moves even if it has no direction specified.
  • With an item directly beneath the reset hook A at (320, 110), light and heavy catches are still retracting after 100 ms, with the heavy catch slower. A bomb at that position retracts and adds 2 points within 80 ms. At 80 ms the explosion is still visible and changes at least 100 canvas pixels. A diamond at that position returns within three seconds.
  • The visible score, explosion and victory agree with gameplay state. Victory uses the current round's default or injected target. Reset clears prior scores, explosions and victory messages.