Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random guess button #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ table.Game-rows > tbody {
justify-content: stretch;
}

.Game-keyboard-button {
.Game-keyboard-button,
.Game-random-guess {
margin: 2px;
background-color: #cdcdcd;
padding: 2px;
Expand Down
2 changes: 2 additions & 0 deletions src/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Row, RowState } from "./Row";
import dictionary from "./dictionary.json";
import { Clue, clue, describeClue, violation } from "./clue";
import { Keyboard } from "./Keyboard";
import { RandomGuess } from "./RandomGuess";
import targetList from "./targets.json";
import {
describeSeed,
Expand Down Expand Up @@ -318,6 +319,7 @@ function Game(props: GameProps) {
letterInfo={letterInfo}
onKey={onKey}
/>
<RandomGuess onKey={onKey} wordLength={wordLength} randomTarget={randomTarget} />
<div className="Game-seed-info">
{challenge
? "playing a challenge game"
Expand Down
27 changes: 27 additions & 0 deletions src/RandomGuess.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
interface GuessProps {
onKey: (key: string) => void;
wordLength: number;
randomTarget: (wordLength: number) => string;
}

export function RandomGuess(props: GuessProps) {
return (
<div className="Game-random" aria-hidden="true">
<div className="Game-random-guess"
tabIndex={-1}
role="button"
onClick={() => {
for (let i = 0; i < props.wordLength; i++) {
props.onKey("Backspace");
}
const guess = props.randomTarget(props.wordLength);
for (const letter of guess) {
props.onKey(letter);
}
}}
>
Random Guess
</div>
</div>
);
}