forked from ReKindleOS/ReKindle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.html
More file actions
398 lines (339 loc) · 11.4 KB
/
Copy pathmemory.html
File metadata and controls
398 lines (339 loc) · 11.4 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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
<meta charset="UTF-8">
<title>Memory</title>
<script src="js/i18n.js"></script>
<style>
/* SYSTEM 7 AESTHETICS */
:root {
--bg-color: #ffffff;
--text-color: #000000;
--border: 2px solid #000000;
--shadow: 4px 4px 0px #000000;
--stripe-pattern: repeating-linear-gradient(0deg, transparent, transparent 2px, #000 3px, #000 4px);
--card-back: #000000;
--card-front: #ffffff;
}
body {
image-rendering: -webkit-crisp-edges;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: pixelated;
image-rendering: crisp-edges;
-ms-interpolation-mode: nearest-neighbor;
background-repeat: repeat;
background-position: top left;
image-rendering: -webkit-optimize-contrast;
image-rendering: pixelated;
image-rendering: crisp-edges;
background-repeat: repeat;
background-position: top left;
image-rendering: pixelated;
image-rendering: crisp-edges;
background-repeat: repeat;
background-position: top left;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: 0;
padding: 20px;
height: 100vh;
overflow: hidden;
background-color: #e5e5e5;
/* Default Background (Overridden by JS) */
/* Background managed by settings */
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
/* FIX: Centers vertically */
user-select: none;
box-sizing: border-box;
}
/* WINDOW FRAME */
.window {
background: white;
border: 2px solid black;
box-shadow: var(--shadow);
display: flex;
flex-direction: column;
height: fit-content;
/* ADAPTIVE HEIGHT */
max-height: 95vh;
width: 90%;
max-width: 600px;
position: relative;
}
/* TITLE BAR */
.title-bar {
height: 35px;
border-bottom: 2px solid black;
display: flex;
align-items: center;
justify-content: center;
background: white;
padding: 0 10px;
position: relative;
flex-shrink: 0;
}
.title-stripes {
position: absolute;
top: 4px;
bottom: 4px;
left: 4px;
right: 4px;
background-image: var(--stripe-pattern);
z-index: 0;
}
.title-text {
background: white;
padding: 0 15px;
font-weight: bold;
z-index: 1;
font-size: 1.1rem;
}
#stats {
position: absolute;
right: 10px;
font-family: "Courier New", monospace;
font-weight: bold;
background: white;
padding: 0 10px;
z-index: 1;
font-size: 0.9rem;
}
/* CLOSE BUTTON (HOME) */
.close-box {
position: absolute;
left: 10px;
width: 18px;
height: 18px;
border: 2px solid black;
background: white;
z-index: 2;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-family: sans-serif;
font-size: 0.9rem;
line-height: 1;
box-shadow: 2px 2px 0 black;
}
.close-box:active {
background: black;
color: white;
transform: translate(1px, 1px);
box-shadow: none;
}
/* GAME AREA */
.window-content {
flex-grow: 1;
overflow-y: auto;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: white;
}
/* GAME GRID */
#game-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
width: 100%;
max-width: 400px;
margin-bottom: 20px;
}
.card {
background-color: var(--card-back);
border: 2px solid black;
border-radius: 6px;
display: flex;
justify-content: center;
align-items: center;
font-size: 2.5rem;
cursor: pointer;
position: relative;
height: 90px;
/* FIX: Explicit height for Kindle */
box-shadow: 2px 2px 0 #ccc;
}
/* Revealed State (White background, Visible Icon) */
.card.revealed {
background-color: var(--card-front);
}
/* Matched State (Inverted/Dimmed to indicate done) */
.card.matched {
background-color: white;
border-color: #ccc;
color: #ccc;
box-shadow: none;
}
/* Icon visibility logic */
.card-icon {
display: none;
}
.card.revealed .card-icon,
.card.matched .card-icon {
display: block;
}
/* CONTROLS */
.controls {
display: flex;
width: 100%;
max-width: 400px;
justify-content: center;
}
button {
background: white;
border: 2px solid black;
color: black;
padding: 10px 20px;
font-weight: bold;
font-size: 1rem;
cursor: pointer;
border-radius: 4px;
text-transform: uppercase;
box-shadow: 3px 3px 0 black;
flex: 1;
}
button:active {
background: black;
color: white;
transform: translate(2px, 2px);
box-shadow: none;
}
</style>
<script src="theme.js"></script>
</head>
<body>
<div class="window">
<div class="title-bar">
<div class="title-stripes"></div>
<!-- Home Button -->
<div class="close-box" onclick="window.location.href='index'">X</div>
<span class="title-text" data-i18n="memory.title">Memory</span>
<div id="stats" data-i18n="memory.label.moves" data-i18n-n="0">Moves: 0</div>
</div>
<div class="window-content">
<div id="game-grid">
<!-- Cards injected here -->
</div>
<div class="controls">
<button onclick="initGame()" data-i18n="memory.btn.reset">Reset</button>
</div>
</div>
</div>
<script>
// --- SYMBOLS ---
const SYMBOLS = ['★', '♠', '♥', '♣', '♦', '●', '▲', '■'];
// --- STATE ---
let cards = []; // Array of card objects
let flippedCards = [];
let moves = 0;
let matches = 0;
let isLocked = false;
// --- INIT ---
window.onload = () => {
if (window.rekindleApplyWallpaper) window.rekindleApplyWallpaper();
initGame();
};
function initGame() {
const grid = document.getElementById('game-grid');
grid.innerHTML = '';
moves = 0;
matches = 0;
const stats = document.getElementById('stats');
stats.innerText = window.t ? window.t('memory.label.moves').replace('${n}', 0) : "Moves: 0";
stats.removeAttribute('data-i18n');
flippedCards = [];
isLocked = false;
// Create pairs
let deck = [...SYMBOLS, ...SYMBOLS];
deck = shuffle(deck);
// Generate HTML
deck.forEach((symbol, index) => {
const card = document.createElement('div');
card.className = 'card';
card.dataset.index = index;
card.onclick = () => handleCardClick(index);
const icon = document.createElement('div');
icon.className = 'card-icon';
icon.innerText = symbol;
card.appendChild(icon);
grid.appendChild(card);
card.dataset.symbol = symbol;
});
}
// --- LOGIC ---
function handleCardClick(index) {
if (isLocked) return;
const card = document.querySelectorAll('.card')[index];
if (card.classList.contains('revealed') || card.classList.contains('matched')) return;
// Reveal
card.classList.add('revealed');
flippedCards.push(card);
if (flippedCards.length === 2) {
moves++;
const stats = document.getElementById('stats');
stats.innerText = window.t ? window.t('memory.label.moves').replace('${n}', moves) : "Moves: " + moves;
stats.removeAttribute('data-i18n');
checkForMatch();
}
}
function checkForMatch() {
isLocked = true;
const [card1, card2] = flippedCards;
if (card1.dataset.symbol === card2.dataset.symbol) {
// Match!
setTimeout(() => {
card1.classList.remove('revealed');
card2.classList.remove('revealed');
card1.classList.add('matched');
card2.classList.add('matched');
matches++;
checkWin();
flippedCards = [];
isLocked = false;
}, 300);
} else {
// No Match
setTimeout(() => {
card1.classList.remove('revealed');
card2.classList.remove('revealed');
flippedCards = [];
isLocked = false;
}, 1000);
}
}
function checkWin() {
if (matches === SYMBOLS.length) {
const stats = document.getElementById('stats');
stats.innerText = window.t ? window.t('memory.msg.done').replace('${n}', moves) : "DONE! Moves: " + moves;
stats.removeAttribute('data-i18n');
// Flash Window Content
const content = document.querySelector('.window-content');
content.style.filter = "invert(1)";
setTimeout(() => {
content.style.filter = "invert(0)";
}, 500);
}
}
// --- UTILS ---
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
</script>
<script>
</script>
<script src="https://cdn.counter.dev/script.js" data-id="4e551911-0e5d-4c48-91a6-b828c3301675"
data-utcoffset="11"></script>
</body>
</html>