File tree Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Expand file tree Collapse file tree 4 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 52
52
< h1 class ="basis-1/2 self-end "> Code Arcade</ h1 >
53
53
< div class ="flex justify-between w-1/2 ">
54
54
< button class ="btn-primary "> ► Run</ button >
55
+ < button class ="btn-tertiary "> ⟳ Restart</ button >
55
56
< button class ="btn-secondary "> ⓘ Hint</ button >
56
57
</ div >
57
58
</ div >
@@ -62,6 +63,7 @@ <h1 class="xl:hidden">Code Arcade</h1>
62
63
< div id ="editor "> </ div >
63
64
< div class ="xl:hidden ">
64
65
< button class ="btn-primary "> ► Run</ button >
66
+ < button class ="btn-tertiary "> ⟳ Restart</ button >
65
67
< button class ="btn-secondary "> ⓘ Hint</ button >
66
68
</ div >
67
69
</ div >
Original file line number Diff line number Diff line change @@ -3,13 +3,15 @@ const audio = new Audio('sounds/score.mp3')
3
3
type Callback = ( ) => void
4
4
5
5
/**
6
- * Attaches click listeners to "Run" and "Hint" buttons.
6
+ * Attaches click listeners to "Run", "Restart", and "Hint" buttons.
7
7
*
8
8
* @param runCallback - Run callback.
9
+ * @param restartCallback - Restart callback.
9
10
* @param hintCallback - Hint callback.
10
11
*/
11
12
export function addEventListeners (
12
13
runCallback : Callback ,
14
+ restartCallback : Callback ,
13
15
hintCallback : Callback ,
14
16
) {
15
17
const runButtons = document . querySelectorAll (
@@ -23,6 +25,17 @@ export function addEventListeners(
23
25
}
24
26
} )
25
27
28
+ const restartButtons = document . querySelectorAll (
29
+ 'main .btn-tertiary' ,
30
+ ) as NodeListOf < HTMLButtonElement >
31
+
32
+ restartButtons . forEach ( ( restartButton ) => {
33
+ restartButton . onclick = ( ) => {
34
+ audio . play ( )
35
+ restartCallback ( )
36
+ }
37
+ } )
38
+
26
39
const hintButtons = document . querySelectorAll (
27
40
'main .btn-secondary' ,
28
41
) as NodeListOf < HTMLButtonElement >
Original file line number Diff line number Diff line change @@ -36,12 +36,23 @@ export async function go(levelNumber: number) {
36
36
} ,
37
37
} )
38
38
39
+ run ( )
40
+
39
41
function run ( ) {
40
42
const script = editorView . state . doc . toString ( )
41
43
iframe . srcdoc = wrapGame ( { ...level , script } )
42
44
}
43
45
44
- run ( )
46
+ function restart ( ) {
47
+ editorView . dispatch ( {
48
+ changes : {
49
+ from : 0 ,
50
+ to : editorView . state . doc . length ,
51
+ insert : level . script ?. trim ( ) ,
52
+ } ,
53
+ } )
54
+ run ( )
55
+ }
45
56
46
57
function hint ( ) {
47
58
iframe . contentWindow ?. postMessage ( {
@@ -50,7 +61,7 @@ export async function go(levelNumber: number) {
50
61
} )
51
62
}
52
63
53
- addEventListeners ( run , hint )
64
+ addEventListeners ( run , restart , hint )
54
65
}
55
66
56
67
/**
Original file line number Diff line number Diff line change 25
25
.btn-secondary {
26
26
@apply bg-blue-500 hover:bg-blue-400 text-white font-bold py-2 px-4 border-b-4 border-blue-700 hover:border-blue-500 rounded;
27
27
}
28
+
29
+ .btn-tertiary {
30
+ @apply bg-yellow-500 hover:bg-yellow-400 text-white font-bold py-2 px-4 border-b-4 border-yellow-700 hover:border-yellow-500 rounded;
31
+ }
28
32
}
29
33
30
34
@layer utilities {
You can’t perform that action at this time.
0 commit comments