Skip to content

Commit caee844

Browse files
authored
Added a list to keep track of player's moves (#488)
Every time you click on a tile, it tracks the indexes of the tiles you pressed ![image](https://github.com/user-attachments/assets/ccecc845-eafe-40d3-ac13-271694deae6c)
1 parent bcd1abe commit caee844

File tree

1 file changed

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

1 file changed

+17
-6
lines changed
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
import React from "react";
1+
import React, { useState } from "react";
22

33
import { Box } from "./Box.tsx";
44
import { playNote } from "../util/playNote.ts";
55
import { config } from "../constants.ts";
66

77
export function App() {
8+
const [playerMoves, setPlayerMoves] = useState<readonly number[]>([]);
89
return (
9-
<div style={{ display: "flex", gap: 10 }}>
10-
{config.boxes.map((box) => (
11-
<Box color={box.color} onClick={() => playNote(box.frequency)} />
12-
))}
13-
</div>
10+
<>
11+
<div style={{ display: "flex", gap: 10 }}>
12+
{config.boxes.map((box, index) => (
13+
<Box
14+
key={index}
15+
color={box.color}
16+
onClick={() => {
17+
playNote(box.frequency);
18+
setPlayerMoves((prev) => [...prev, index]);
19+
}}
20+
/>
21+
))}
22+
</div>
23+
<pre>{JSON.stringify(playerMoves, null, 2)}</pre>
24+
</>
1425
);
1526
}

0 commit comments

Comments
 (0)