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

Dark-themed Tetris

Build a playable, dark-themed Tetris game. Deliver a root index.html that opens directly in a browser and works offline. Render the falling piece and locked blocks on a board of at least 8 columns and 12 rows, and display the score and cleared-line count.

Gameplay

Use Left and Right to move, Up to rotate, and Down to drop one row. Respect walls and existing blocks. When a piece cannot drop farther, lock it, clear completed rows, shift the remaining rows down, increase the score and line count for cleared rows, and spawn the next piece. If the new piece cannot spawn, end the game and freeze play until reset.

State and time interface

Expose window.gameTest with reset(), setBoard(rows), setPiece(piece), move(dx), rotate(), drop(), step(milliseconds), and state(). Drive the same state and rendering as the keyboard controls, with changes visible on the page.

  • Return {rows, cols, board, piece:{shape, x, y, color}, score, lines, gameOver}. setBoard takes a two-dimensional array of the reported dimensions. Cells with 0 or null are empty; 1 is occupied and renders visibly. Occupied cells may also be stored as color strings. setPiece installs the supplied shape and coordinates, with a default color if omitted.
  • drop() follows the same single-row or lock-and-spawn behavior as Down. step(milliseconds) drops once per accumulated 500 ms, preserving leftover time. Zero or less than 500 ms of accumulated time does not drop a piece.
  • reset(), setBoard() and setPiece() clear leftover time. After any of these calls, the deterministic scenario advances only through explicit actions, not the page's live clock. Reset restores an empty playable board, zero score and zero cleared lines.

Acceptance Checklist

  • The offline entry renders without browser errors. Movement, rotation and drops affect the real board and respect collisions. Movement and injected occupied cells are visible.
  • A full row disappears, the board gains an empty top row, and both line count and score increase.
  • Sub-interval time accumulates across calls, and a large step can drop several rows. Board and piece injection and reset clear leftover time; the live clock does not advance an injected state.
  • A blocked spawn sets gameOver; subsequent move, rotate, drop and step calls leave state unchanged until reset restores play.