← 返回 ramp 的题目列表Build a Wordle Mini Game (React)
类型:online_judge
Problem: Build a Simplified Wordle Mini Game in React (No Styling Required)
Implement an interactive Wordle-like mini game using React. No CSS/styling is required; focus on correct functionality.
Game Rules
The game is initialized with a target word answer (e.g., "APPLE").
The player has up to maxAttempts attempts to guess the word.
Each guess must be a string with the same length as answer.
After submitting a guess, return per-character feedback:
green: correct letter in the correct position.
yellow: letter exists in answer but in a different position (must handle duplicates correctly).
gray: letter does not exist in answer.
Functional Requirements
Provide a way for the user to enter the current guess (an <input> or a grid-based input are both acceptable).
On submission (button click or Enter key), append the guess to a history list and display feedback for each character (green/yellow/gray).
The game ends when:
The player guesses answer (win), or
The player uses maxAttempts guesses without matching answer (lose).
After the game ends, prevent further submissions and display the result (e.g., "You win" / "You lose").
Constraints and Edge Cases
Assume only English letters; treat input as case-insensitive (normalize to uppercase).
If the guess length is not answer.length, block submission or show an error.
Correctly handle duplicate letters in either answer or the guess (e.g., answer=LEVEL, guess=LEECH).
Typical Limits
answer.length: typically 5.
maxAttempts: typically 6.
Example
answer = "APPLE"
guess = "ALLEY"
feedback:
A: green
L: yellow (L exists in answer but only once)
L: gray (second L exceeds the count in answer)
E: yellow
Y: gray
Example
Input
answer=APPLE\nmaxAttempts=6\nguess=ALLEY
Output
[green,yellow,gray,yellow,gray] and game continues