File tree Expand file tree Collapse file tree 1 file changed +64
-7
lines changed
content/tutorial/02-advanced-svelte/09-special-elements/10-svelte-fragment/app-b/src/lib Expand file tree Collapse file tree 1 file changed +64
-7
lines changed Original file line number Diff line number Diff line change 1
1
<script >
2
- import Box from ' ./Box.svelte' ;
2
+ import Board from ' ./Board.svelte' ;
3
+ import { getWinningLine } from ' ./utils.js' ;
4
+
5
+ let squares = Array (9 ).fill (' ' );
6
+ let next = ' x' ;
7
+
8
+ $: winningLine = getWinningLine (squares);
3
9
</script >
4
10
5
- <Box >
6
- <svelte:fragment slot =" footer" >
7
- <p >All rights reserved.</p >
8
- <p >Copyright (c) 2019 Svelte Industries</p >
9
- </svelte:fragment >
10
- </Box >
11
+ <div class =" container" >
12
+ <Board size ={3 }>
13
+ <svelte:fragment slot =" game" >
14
+ {#each squares as square , i }
15
+ <button
16
+ class =" square"
17
+ class:winning ={winningLine ?.includes (i )}
18
+ disabled ={square }
19
+ on:click ={() => {
20
+ squares [i ] = next ;
21
+ next = next === ' x' ? ' o' : ' x' ;
22
+ }}
23
+ >
24
+ {square }
25
+ </button >
26
+ {/each }
27
+ </svelte:fragment >
28
+
29
+ <div slot =" controls" >
30
+ <button on:click ={() => {
31
+ squares = Array (9 ).fill (' ' );
32
+ next = ' x' ;
33
+ }}>
34
+ Reset
35
+ </button >
36
+ </div >
37
+ </Board >
38
+ </div >
39
+
40
+ <style >
41
+ .container {
42
+ display : flex ;
43
+ flex-direction : column ;
44
+ gap : 1em ;
45
+ align-items : center ;
46
+ justify-content : center ;
47
+ height : 100% ;
48
+ margin : 0 auto ;
49
+ }
50
+
51
+ .square , .square :disabled {
52
+ background : white ;
53
+ border-radius : 0 ;
54
+ color : #222 ;
55
+ opacity : 1 ;
56
+ font-size : 2em ;
57
+ padding : 0 ;
58
+ }
59
+
60
+ .winning {
61
+ font-weight : bold ;
62
+ }
63
+
64
+ .container :has (.winning ) .square :not (.winning ) {
65
+ color : #ccc ;
66
+ }
67
+ </style >
You can’t perform that action at this time.
0 commit comments