Skip to content

Commit 195415b

Browse files
authored
Added randNum and updated correct moves (#502)
1 parent a315cef commit 195415b

File tree

1 file changed

+9
-6
lines changed
  • workspaces/simon-game/src/app/components

1 file changed

+9
-6
lines changed

workspaces/simon-game/src/app/components/App.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@ import { config } from "../constants.ts";
66

77
type GameState = "pre-game" | "game-over" | "player-turn" | "cpu-turn";
88

9+
// TODO: Move this to a new file later
10+
function randNum(upperBound: number): number {
11+
return Math.floor(Math.random() * upperBound);
12+
}
13+
914
export function App() {
1015
const [playerMoves, setPlayerMoves] = useState<readonly number[]>([]);
1116
const [gameState, setGameState] = useState<GameState>("pre-game");
12-
const [_correctMoves, _setCorrectMoves] = useState<readonly number[]>([
13-
0, 1, 2, 3,
14-
]);
15-
16-
console.log(_correctMoves, _setCorrectMoves);
17+
const [correctMoves, setCorrectMoves] = useState<readonly number[]>([]);
1718

1819
if (gameState === "pre-game") {
1920
return (
2021
<div style={{ display: "flex", gap: 10 }}>
2122
<button
2223
onClick={() => {
2324
setGameState("cpu-turn");
25+
setCorrectMoves((prev) => [...prev, randNum(4)]); // TODO: Add to cpu-turn state instead once created
2426
}}
2527
>
2628
Start Game
@@ -44,7 +46,8 @@ export function App() {
4446
/>
4547
))}
4648
</div>
47-
<pre>{JSON.stringify(playerMoves, null, 2)}</pre>
49+
<pre>Player Moves: {JSON.stringify(playerMoves, null, 2)}</pre>
50+
<pre>Correct Moves: {JSON.stringify(correctMoves, null, 2)}</pre>
4851
</>
4952
);
5053
}

0 commit comments

Comments
 (0)