-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
executable file
·248 lines (220 loc) · 10.2 KB
/
index.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="author" content="Dmitry Sharabin" />
<meta name="keywords" content="HTML,CSS,Udacity,Nanodegree,Mavo" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<!-- Mavo -->
<link rel="stylesheet prefetch" href="https://get.mavo.io/mavo.min.css" />
<script src="https://get.mavo.io/mavo.min.js"></script>
<!-- Shoelace -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.18.0/cdn/themes/light.css" />
<script type="module" src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.18.0/cdn/shoelace-autoloader.js"></script>
<!-- NudeUI -->
<script src="https://nudeui.com/elements/meter-discrete/meter-discrete.js" type="module"></script>
<link rel="stylesheet prefetch" href="css/style.css" />
<link rel="icon" href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">🧠</text></svg>' />
<title>Memory Game</title>
</head>
<body>
<header mv-app="header" style="--theme-color: [game.color || 'initial']">
<h1>Memory Game</h1>
<h2>
<meta property="themeNumber" mv-default="[random(0, count(themes.theme) - 1)]" mv-mode="read" />
<sl-dropdown class="theme-picker">
<sl-button slot="trigger" caret mv-value="get(game.gameTheme, 'name')">Emoji</sl-button>
<sl-menu mv-list mv-value="themes.theme">
<sl-menu-label>Themes</sl-menu-label>
<sl-menu-item
mv-list-item
value="[$index]"
mv-group
mv-action="if(themeNumber != $index,
set(game.card.flipped, false) &
set(game.card.state, '') &
set(game.move, 0) &
set(game.gameStarted, false) &
set(themeNumber, $index) &
set(game.symbols, shuffle(game.symbols))
)">
[name]
<span slot="prefix" mv-value="get(get(themes.theme, $index).symbols, random(0, 7))">🧠</span>
</sl-menu-item>
</sl-menu>
</sl-dropdown>
<button mv-action="
set(game.card.flipped, false)
set(game.card.state, '')
set(game.move, 0)
set(game.gameStarted, false)
set(themeNumber, random(0, count(themes.theme) - 1))
set(game.symbols, shuffle(game.symbols))
">
<svg>
<title>Random Theme</title>
<use xlink:href="#icon-shuffle" />
</svg>
</button>
</h2>
</header>
<main>
<section mv-app="gameState">
<meter-discrete value="[game.rating]" max="3"></meter-discrete>
<div id="moves-counter" mv-value="[pluralize(game.move, 'move', 'moves')]">0 moves</div>
<div id="timer" mv-value="if(game.gameStarted = true, game.timer, '00:00')">00:00</div>
<svg mv-action="
set(game.card.flipped, false)
set(game.card.state, '')
set(game.move, 0)
set(game.gameStarted, false)
set(game.symbols, shuffle(game.symbols))
">
<title>Reset Game</title>
<use xlink:href="#icon-reset" />
</svg>
</section>
<section mv-app="game" mv-mode="read">
<!-- Settings -->
<meta property="themeNumber" content="[header.themeNumber || 0]" />
<meta property="gameTheme" content="[get(themes.theme, themeNumber)]" />
<meta property="symbols" content="[get(gameTheme, 'symbols')]" />
<meta property="color" content="[get(gameTheme, 'color')]" />
<!-- Game state -->
<meta property="move" content="0" />
<meta property="rating" content="[if(move < 19, 3, if(move < 26, 2, if(move < 32, 1, 0)))]" />
<meta property="gameStarted" />
<meta property="startTime" />
<meta property="gameOver" content="[count(card where starts(state, 'matched-')) = count(card)]" />
<meta property="minutes" content="[minutes($now - startTime) mod 60]" />
<meta property="seconds" content="[seconds($now - startTime) mod 60]" />
<meta property="timer" content="[if(minutes < 10, 0 & minutes, minutes)]:[if(seconds < 10, 0 & seconds, seconds)]" />
<meta property="firstCard" content="©" />
<ul id="game-board" mv-list mv-value="shuffle(list(symbols, symbols))" style="--theme-color: [color]">
<li mv-list-item class="card [if(flipped, 'flipped')] [state]"
mv-action="
if(move = 0, set(gameStarted, true) & set(startTime, time($now, 'ms')))
setif(move mod 2 = 0 and !starts(state, 'incorrect-') and count(starts(state.$all, 'incorrect-')) > 0, filter($all, starts(state.$all, 'incorrect-')).state, '')
setif(move mod 2 = 0 and !starts(state, 'incorrect-') and !starts(state, 'matched-') and count(flipped.$all) > 0, flipped.$all, false)
setif(!flipped and !starts(state, 'incorrect-') and !starts(state, 'matched-'), move, move + 1)
setif(!flipped and !starts(state, 'matched-'), flipped, true)
if(move mod 2 = 0 and symbol = firstCard, set(filter($all, flipped.$all).state, 'matched-first') & set(state, 'matched-second'))
if(move mod 2 = 0 and firstCard != '©' and symbol != firstCard, set(filter($all, flipped.$all).state, 'incorrect-first') & set(state, 'incorrect-second'))
setif(move mod 2 = 0, firstCard, '©')
setif(move mod 2 = 1 and !starts(state, 'matched-'), firstCard, symbol)
addif(count(starts(state.$all, 'matched-')) = count($all), group(theme: get(gameTheme, 'name'), moves: move, stars: rating, time: timer), stats.attempts)
">
<meta property="state" />
<meta property="flipped" datatype="boolean" content="false" />
<span property="symbol"></span>
</li>
</ul>
</section>
<details mv-app="themes" mv-init="themes.json" mv-storage="local" mv-autosave mv-bar="with import export" mv-mode="edit">
<summary class="mv-bar">Themes</summary>
<ul mv-list mv-initial-items="0">
<li mv-list-item="theme">
<div class="inputs">
<input type="text" property="name" placeholder="Theme name" />
<input type="color" property="color" mv-default="#938cf2" />
</div>
<details class="symbols" open>
<summary>Symbols</summary>
<ul mv-list="symbols" mv-initial-items="8" mv-item-bar="no-delete no-add" style="--theme-color: [color]">
<li mv-list-item aria-label="Card symbol" mv-editor-placeholder="💩"></li>
</ul>
</details>
</li>
</ul>
</details>
<table mv-app="stats" mv-storage="local" mv-autosave mv-mode="read">
<caption>
Attempts Results
<svg mv-action="clear(attempts)">
<title>Clear Results</title>
<use xlink:href="#icon-bin" />
</svg>
</caption>
<thead>
<tr>
<th>Attempt</th>
<th>Theme</th>
<th>Moves</th>
<th>Stars</th>
<th>Time</th>
</tr>
</thead>
<tbody mv-list="attempts" mv-initial-items="0">
<tr mv-if="count(attempts) = 0">
<td colspan="5">There are no attempts yet!</td>
</tr>
<tr mv-list-item>
<td mv-value="$index + 1">1</td>
<td property="theme">emoji</td>
<td property="moves">16</td>
<td property="stars">3</td>
<td property="time">00:35</td>
</tr>
</tbody>
</table>
</main>
<footer>
Made with <a href="https://mavo.io"><img src="https://mavo.io/logo.svg" alt="Mavo logo" /></a>
</footer>
<!-- Modal window with the result of the game -->
<div id="game-over" mv-app class="[if(game.gameOver, 'game-over')]" style="--theme-color: [game.color]">
<meta property="attempt" content="[last(stats.attempts)]" />
<meta property="moves" content="[get(attempt, 'moves')]" />
<meta property="stars" content="[get(attempt, 'stars')]" />
<meta property="time" content="[get(attempt, 'time')]" />
<svg>
<use xlink:href="#icon-checkmark" />
</svg>
<h2 class="[if(game.gameOver, boom)]">Congratulations!
You Won!
</h2>
<p>
You made [pluralize(moves, "move", "moves")]
and earned [if(stars = 0, "no stars", pluralize(stars, "star", "stars"))].
It took you [time] min.
</p>
<button mv-action="
set(game.card.flipped, false)
set(game.card.state, '')
set(game.move, 0)
set(game.gameStarted, false)
set(game.symbols, shuffle(game.symbols))
set(header.themeNumber, random(0, count(themes.theme) - 1))
">Play again!</button>
</div>
<!--
Icon System
See “Practical SVG” by Chris Coyier (https://abookapart.com/products/practical-svg)
Icons source: https://icomoon.io/app/#/select
-->
<svg aria-hidden="true" width="0" height="0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-reset" viewBox="0 0 32 32">
<title>Reset Game</title>
<path d="M27.802 5.197c-2.925-3.194-7.13-5.197-11.803-5.197-8.837 0-16 7.163-16 16h3c0-7.18 5.82-13 13-13 3.844 0 7.298 1.669 9.678 4.322l-4.678 4.678h11v-11l-4.198 4.197z"></path>
<path d="M29 16c0 7.18-5.82 13-13 13-3.844 0-7.298-1.669-9.678-4.322l4.678-4.678h-11v11l4.197-4.197c2.925 3.194 7.13 5.197 11.803 5.197 8.837 0 16-7.163 16-16h-3z"></path>
</symbol>
<symbol id="icon-bin" viewBox="0 0 32 32">
<title>Clear Results</title>
<path d="M4 10v20c0 1.1 0.9 2 2 2h18c1.1 0 2-0.9 2-2v-20h-22zM10 28h-2v-14h2v14zM14 28h-2v-14h2v14zM18 28h-2v-14h2v14zM22 28h-2v-14h2v14z"></path>
<path d="M26.5 4h-6.5v-2.5c0-0.825-0.675-1.5-1.5-1.5h-7c-0.825 0-1.5 0.675-1.5 1.5v2.5h-6.5c-0.825 0-1.5 0.675-1.5 1.5v2.5h26v-2.5c0-0.825-0.675-1.5-1.5-1.5zM18 4h-6v-1.975h6v1.975z"></path>
</symbol>
<symbol id="icon-checkmark" viewBox="0 0 1000 1000">
<title>Checkmark</title>
<path d="M500,10C229.3,10,10,229.3,10,500c0,270.7,219.3,490,490,490s490-219.3,490-490C990,229.3,770.5,10,500,10z M500,968.5C241.4,968.5,31.5,758.6,31.5,500C31.5,241.4,241.4,31.5,500,31.5c258.6,0,468.5,209.8,468.5,468.5C968.5,758.6,758.6,968.5,500,968.5z"></path>
<path d="M211.9,441.1l-89.2,118.3c0,0,193.3,156,257.9,266.2c0,0,214.8-355.6,466.3-512.4l-99.3-118.3c0,0-232.4,162.6-357.2,423.8C390.5,618.5,293.1,506.3,211.9,441.1z"></path>
</symbol>
<symbol id="icon-shuffle" viewBox="0 0 72 72">
<title>Random Theme</title>
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="m40.377 40.458l6.91 6.934c1.614 1.619 4.095 2.566 6.724 2.566h12.775M5 21.958h12.775c2.629 0 5.11.948 6.724 2.567l7.023 7.047M5 49.958h12.775c2.629 0 5.11-.947 6.724-2.566l22.788-22.867c1.614-1.62 4.095-2.567 6.724-2.567h12.775m0 0L58.6 13.744m0 16.428l8.186-8.214m0 28L58.6 41.744m0 16.428l8.186-8.214" />
</symbol>
</defs>
</svg>
</body>
</html>