-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimon.tsx
More file actions
61 lines (57 loc) · 2.34 KB
/
simon.tsx
File metadata and controls
61 lines (57 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { useGameMachine } from './components/use-game-machine';
import { GameOverModal } from './components/game-over-modal';
import { usePadController } from './components/use-pad-controller';
import {
useGetHighScoreApi,
useUpdateHighScoreApi,
} from './services/api.high-score';
import { Button } from './components/ui.button';
import { HighScoreDisplay } from './components/high-score-display';
import { Pads } from './components/pads';
export function Simon() {
const getHighScoreApi = useGetHighScoreApi();
const updateHighScoreApi = useUpdateHighScoreApi();
const gameMachine = useGameMachine({
currentHighScore: getHighScoreApi.data?.highScore,
});
const padController = usePadController({
onUserPadDown: gameMachine.actions.input,
disabled: gameMachine.isComputerTurn,
});
return (
<main className="font-sans text-slate-200 overflow-hidden fixed h-dvh w-full touch-none bg-gradient-to-b from-slate-700 to-sky-950 flex items-center justify-center">
<div className="w-full h-full flex flex-col landscape:flex-row max-w-screen-2xl items-center justify-evenly">
<section className="h-24 landscape:h-auto w-full flex items-center justify-center">
{!gameMachine.isPlaying && (
<HighScoreDisplay getHighScoreApi={getHighScoreApi} />
)}
</section>
<section aria-label="gamepad">
<Pads
isPlaying={gameMachine.isPlaying}
isUserTurn={gameMachine.isUserTurn}
currentScore={gameMachine.currentScore}
padController={padController}
/>
</section>
<section className="h-24 landscape:h-auto w-full flex items-center justify-center">
{!gameMachine.isPlaying && (
<Button onClick={gameMachine.actions.startNewGame}>
<span className="text-xl md:text-2xl font-bold">start</span>
</Button>
)}
</section>
</div>
{gameMachine.isGameOver && (
<GameOverModal
userScore={gameMachine.userScore}
isNewHighScore={gameMachine.isNewHighScore}
onModalClose={() => gameMachine.actions.transition({ to: 'newGame' })}
pausePadKeyListeners={padController.padKeyListeners.pause}
getHighScoreApi={getHighScoreApi}
updateHighScoreApi={updateHighScoreApi}
/>
)}
</main>
);
}