1
- import React , { useState , useEffect } from 'react' ;
2
- import { Terminal , Brain , Shield , Zap , VolumeX , Volume2 } from 'lucide-react' ;
1
+ import React , { useEffect , useState } from 'react' ;
2
+ import { Brain , Shield , Terminal , Volume2 , VolumeX , Zap } from 'lucide-react' ;
3
3
import { Alert , AlertDescription , AlertTitle } from '@/components/ui/alert' ;
4
4
import { Button } from '@/components/ui/button' ;
5
5
import {
6
6
Card ,
7
- CardHeader ,
8
7
CardContent ,
9
8
CardFooter ,
9
+ CardHeader ,
10
10
} from '@/components/ui/card' ;
11
11
import { Progress } from '@/components/ui/progress' ;
12
12
import { Badge } from '@/components/ui/badge' ;
@@ -43,16 +43,16 @@ const OpenEHRQuest: React.FC = () => {
43
43
isCorrect : false ,
44
44
} ) ;
45
45
const [ soundEnabled , setSoundEnabled ] = useState ( true ) ;
46
- const { playCorrectSound, playWrongSound, playCompletionSound } =
47
- useSoundEffects ( ) ;
46
+ const { playCorrectSound, playWrongSound, playCompletionSound }
47
+ = useSoundEffects ( ) ;
48
48
49
49
const levels = levelsData ;
50
50
51
51
useEffect ( ( ) => {
52
52
if (
53
- gameState . currentLevel >= levels . length &&
54
- levels . length > 0 &&
55
- soundEnabled
53
+ gameState . currentLevel >= levels . length
54
+ && levels . length > 0
55
+ && soundEnabled
56
56
) {
57
57
playCompletionSound ( ) ;
58
58
}
@@ -68,16 +68,19 @@ const OpenEHRQuest: React.FC = () => {
68
68
const isCorrect = selectedIndex === currentLevel . correctAnswer ;
69
69
70
70
if ( isCorrect ) {
71
- if ( soundEnabled ) playCorrectSound ( ) ;
72
- setGameState ( ( prevState ) => ( {
71
+ if ( soundEnabled )
72
+ playCorrectSound ( ) ;
73
+ setGameState ( prevState => ( {
73
74
...prevState ,
74
75
score : prevState . score + ( prevState . hintUsed ? 50 : 100 ) ,
75
76
answerSelected : true ,
76
77
isCorrect : true ,
77
78
} ) ) ;
78
- } else {
79
- if ( soundEnabled ) playWrongSound ( ) ;
80
- setGameState ( ( prevState ) => ( {
79
+ }
80
+ else {
81
+ if ( soundEnabled )
82
+ playWrongSound ( ) ;
83
+ setGameState ( prevState => ( {
81
84
...prevState ,
82
85
playerHealth : Math . max ( 0 , prevState . playerHealth - 20 ) ,
83
86
answerSelected : true ,
@@ -87,7 +90,7 @@ const OpenEHRQuest: React.FC = () => {
87
90
} ;
88
91
89
92
const nextLevel = ( ) => {
90
- setGameState ( ( prevState ) => ( {
93
+ setGameState ( prevState => ( {
91
94
...prevState ,
92
95
currentLevel : prevState . currentLevel + 1 ,
93
96
hintUsed : false ,
@@ -101,7 +104,7 @@ const OpenEHRQuest: React.FC = () => {
101
104
} ;
102
105
103
106
const useHint = ( ) => {
104
- setGameState ( ( prevState ) => ( { ...prevState , hintUsed : true } ) ) ;
107
+ setGameState ( prevState => ( { ...prevState , hintUsed : true } ) ) ;
105
108
} ;
106
109
107
110
const resetGame = ( ) => {
@@ -131,7 +134,10 @@ const OpenEHRQuest: React.FC = () => {
131
134
< p className = "text-center mb-4" >
132
135
Your OpenEHR journey has come to an end.
133
136
</ p >
134
- < p className = "text-center mb-4" > Final Score: { gameState . score } </ p >
137
+ < p className = "text-center mb-4" >
138
+ Final Score:
139
+ { gameState . score }
140
+ </ p >
135
141
</ CardContent >
136
142
< CardFooter >
137
143
< Button onClick = { resetGame } className = "w-full" >
@@ -157,10 +163,13 @@ const OpenEHRQuest: React.FC = () => {
157
163
< p className = "text-center mb-4" >
158
164
You've become an OpenEHR Integration Master!
159
165
</ p >
160
- < p className = "text-center mb-4" > Final Score: { gameState . score } </ p >
166
+ < p className = "text-center mb-4" >
167
+ Final Score:
168
+ { gameState . score }
169
+ </ p >
161
170
< div className = "flex flex-wrap justify-center gap-2 mt-4" >
162
- { gameState . badges . map ( ( badge , index ) => (
163
- < Badge key = { index } variant = "secondary" >
171
+ { gameState . badges . map ( badge => (
172
+ < Badge key = { badge } variant = "secondary" >
164
173
{ badge }
165
174
</ Badge >
166
175
) ) }
@@ -184,7 +193,7 @@ const OpenEHRQuest: React.FC = () => {
184
193
185
194
return parts . map ( ( part , index ) => {
186
195
if ( part === '\n\n' ) {
187
- return < br key = { `br-${ index } ` } /> ;
196
+ return < br key = { `br-${ part } - ${ index } ` } /> ;
188
197
}
189
198
190
199
if ( part . trim ( ) . startsWith ( '<' ) || part . trim ( ) . startsWith ( '{' ) ) {
@@ -194,15 +203,15 @@ const OpenEHRQuest: React.FC = () => {
194
203
if ( inCodeBlock ) {
195
204
return (
196
205
< CodeHighlight
197
- key = { `code-${ index } ` }
206
+ key = { `code-${ part } - ${ index } ` }
198
207
code = { part . trim ( ) }
199
208
language = { language }
200
209
/>
201
210
) ;
202
211
}
203
212
204
213
return (
205
- < p key = { `text-${ index } ` } className = "mb-2" >
214
+ < p key = { `text-${ part } - ${ index } ` } className = "mb-2" >
206
215
{ part }
207
216
</ p >
208
217
) ;
@@ -215,16 +224,24 @@ const OpenEHRQuest: React.FC = () => {
215
224
< CardHeader className = "flex flex-row justify-between items-center" >
216
225
< h1 className = "text-2xl font-bold" > { currentLevel . title } </ h1 >
217
226
< Button onClick = { toggleSound } variant = "ghost" size = "icon" >
218
- { soundEnabled ? (
219
- < Volume2 className = "h-4 w-4" />
220
- ) : (
221
- < VolumeX className = "h-4 w-4" />
222
- ) }
227
+ { soundEnabled
228
+ ? (
229
+ < Volume2 className = "h-4 w-4" />
230
+ )
231
+ : (
232
+ < VolumeX className = "h-4 w-4" />
233
+ ) }
223
234
</ Button >
224
235
</ CardHeader >
225
236
< CardContent >
226
237
< p className = "text-center text-gray-600 mb-4" >
227
- Level { gameState . currentLevel + 1 } of { levels . length }
238
+ Level
239
+ { ' ' }
240
+ { gameState . currentLevel + 1 }
241
+ { ' ' }
242
+ of
243
+ { ' ' }
244
+ { levels . length }
228
245
</ p >
229
246
< Progress
230
247
value = { ( ( gameState . currentLevel + 1 ) / levels . length ) * 100 }
@@ -239,12 +256,13 @@ const OpenEHRQuest: React.FC = () => {
239
256
< h2 className = "text-xl font-semibold mb-2" > Challenge:</ h2 >
240
257
< div className = "bg-gray-800 text-white p-4 rounded-md overflow-x-auto whitespace-pre-wrap break-words" >
241
258
{ renderChallenge ( currentLevel . challenge , currentLevel . language ) }
242
- </ div > { ' ' }
259
+ </ div >
260
+ { ' ' }
243
261
</ div >
244
262
< div className = "space-y-2" >
245
263
{ currentLevel . options . map ( ( option , index ) => (
246
264
< Button
247
- key = { index }
265
+ key = { ` ${ gameState . currentLevel } - ${ index } ` }
248
266
onClick = { ( ) => handleAnswer ( index ) }
249
267
className = "w-full justify-start text-left whitespace-normal h-auto"
250
268
variant = "outline"
@@ -280,7 +298,9 @@ const OpenEHRQuest: React.FC = () => {
280
298
onClick = { useHint }
281
299
disabled = { gameState . hintUsed || gameState . answerSelected }
282
300
>
283
- < Zap className = "mr-2 h-4 w-4" /> Use Hint
301
+ < Zap className = "mr-2 h-4 w-4" />
302
+ { ' ' }
303
+ Use Hint
284
304
</ Button >
285
305
</ TooltipTrigger >
286
306
< TooltipContent >
@@ -293,8 +313,8 @@ const OpenEHRQuest: React.FC = () => {
293
313
</ Tooltip >
294
314
</ TooltipProvider >
295
315
< div className = "flex gap-2" >
296
- { gameState . badges . slice ( - 3 ) . map ( ( badge , index ) => (
297
- < Badge key = { index } variant = "secondary" >
316
+ { gameState . badges . slice ( - 3 ) . map ( badge => (
317
+ < Badge key = { badge } variant = "secondary" >
298
318
{ badge }
299
319
</ Badge >
300
320
) ) }
@@ -312,11 +332,18 @@ const OpenEHRQuest: React.FC = () => {
312
332
< div className = "flex justify-between w-full mb-2" >
313
333
< div className = "flex items-center" >
314
334
< Brain className = "mr-2" />
315
- < span > Score: { gameState . score } </ span >
335
+ < span >
336
+ Score:
337
+ { gameState . score }
338
+ </ span >
316
339
</ div >
317
340
< div className = "flex items-center" >
318
341
< Shield className = "mr-2" />
319
- < span > Health: { gameState . playerHealth } %</ span >
342
+ < span >
343
+ Health:
344
+ { gameState . playerHealth }
345
+ %
346
+ </ span >
320
347
</ div >
321
348
</ div >
322
349
< HealthBar health = { gameState . playerHealth } />
0 commit comments