UXInteract / task_048 /instruction.md
DojiSum's picture
Publish the current 141-task UXInteract release
ef987bb verified
|
Raw History Blame Contribute Delete
2.28 kB
# Build an interactive Minesweeper game
Create a single offline `index.html` in HTML/CSS/JavaScript. Provide a visible board, status, size selector and New Game button.
## Controls and state API
- Use `data-testid="board"`, `"status"`, `"grid-size"` and `"new-game"` on the corresponding elements. Put the state value (`playing`, `won` or `lost`) as text in the status element; any explanatory label can sit outside it. Mark every cell with zero-based `data-r` and `data-c`. Left-click reveals; right-click toggles a flag. Display a text symbol in flagged cells.
- The selector shows dimensions, including 5×5, 8×8 and 12×12; option values may vary. Default to 5×5.
- Expose `window.__game` with `init(config)`, `getState()`, `reveal(r,c)` and `toggleFlag(r,c)`. The three actions return the resulting state and drive the visible board.
- `init` accepts `{rows,cols,mines?}`. Missing dimensions use the current selected size. When `mines` is supplied, use exactly those zero-based `[r,c]` positions. When omitted, sample distinct positions uniformly, with at least one mine and at least one safe cell; consecutive same-size games must not repeat the complete layout.
- `getState()` returns an independent JSON snapshot `{rows,cols,status,cells}`, with `status` equal to `playing`, `won` or `lost`; `cells` is a row-major array of `{revealed,flagged,mine,adj}`. The first three cell fields are booleans and `adj` is the number of mines among eight neighbors.
## Acceptance Checklist
- A new game uses the selected size, renders the full grid, and starts with every cell hidden and unflagged. Number labels, flags and the status are readable; cells are visible and do not overlap.
- Revealing a zero-count cell opens its connected zero region and adjacent numbered boundary cells, using the eight-neighbor grid and never propagating through numbers. Hidden flags toggle on and off, and revealing a flagged cell has no effect.
- Revealing a mine sets and displays `lost` and reveals every mine. Revealing all safe cells sets and displays `won`. Once ended, further reveal or flag actions do not change the board.
- Visible actions and API calls update the same board. Changing the returned state cannot alter it; the game runs without browser errors or external dependencies.