Spaces:
Running
Running
Update index.html
Browse files- index.html +44 -37
index.html
CHANGED
@@ -5,7 +5,6 @@
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>π Apple Merge</title>
|
7 |
<style>
|
8 |
-
/* (μ€νμΌμ μ΄μ κ³Ό λμΌ) */
|
9 |
body {
|
10 |
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
|
11 |
display: flex;
|
@@ -64,8 +63,8 @@
|
|
64 |
}
|
65 |
|
66 |
.grid-cell {
|
67 |
-
width: 100%;
|
68 |
-
height: 100%;
|
69 |
box-sizing: border-box;
|
70 |
position: relative;
|
71 |
border-radius: 8px;
|
@@ -103,7 +102,7 @@
|
|
103 |
|
104 |
.apple span {
|
105 |
font-size: 0.5em;
|
106 |
-
color: #
|
107 |
font-weight: bold;
|
108 |
z-index: 3;
|
109 |
pointer-events: none;
|
@@ -112,7 +111,7 @@
|
|
112 |
top: 50%;
|
113 |
left: 50%;
|
114 |
transform: translate(-50%, -50%);
|
115 |
-
text-shadow:
|
116 |
}
|
117 |
|
118 |
.apple.selected {
|
@@ -320,14 +319,17 @@
|
|
320 |
startCell = null;
|
321 |
event.preventDefault();
|
322 |
}
|
323 |
-
|
324 |
function selectApplesInBox() {
|
325 |
const boxRect = selectionBox.getBoundingClientRect();
|
326 |
-
const containerRect = gameContainer.getBoundingClientRect();
|
327 |
const apples = document.querySelectorAll('.apple');
|
328 |
|
329 |
-
//
|
330 |
-
const selectionMargin = boxRect.width * 0.2;
|
|
|
|
|
|
|
|
|
331 |
|
332 |
apples.forEach(apple => {
|
333 |
const appleRect = apple.getBoundingClientRect();
|
@@ -336,42 +338,47 @@
|
|
336 |
const appleCenterX = appleRect.left + appleRect.width / 2 - containerRect.left;
|
337 |
const appleCenterY = appleRect.top + appleRect.height / 2 - containerRect.top;
|
338 |
|
339 |
-
|
340 |
-
// μ ν μμμ "μμͺ½" κ²½κ³ κ³μ° (margin μ μ©)
|
341 |
-
const innerBoxLeft = boxRect.left - containerRect.left + selectionMargin;
|
342 |
-
const innerBoxTop = boxRect.top - containerRect.top + selectionMargin;
|
343 |
-
const innerBoxRight = boxRect.right - containerRect.left - selectionMargin;
|
344 |
-
const innerBoxBottom = boxRect.bottom - containerRect.top- selectionMargin;
|
345 |
-
|
346 |
-
|
347 |
-
// μ€μ¬μ μ΄ "μμͺ½" μ ν μμ λ΄μ μλμ§ νμΈ
|
348 |
const isInside = appleCenterX >= innerBoxLeft && appleCenterX <= innerBoxRight &&
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
}
|
357 |
-
} else {
|
358 |
-
apple.classList.remove('selected');
|
359 |
-
selectedApples = selectedApples.filter(a => a !== apple);
|
360 |
-
}
|
361 |
});
|
362 |
-
|
363 |
-
|
364 |
function deselectAllApples() {
|
365 |
selectedApples.forEach(apple => apple.classList.remove('selected'));
|
366 |
selectedApples = [];
|
367 |
}
|
368 |
|
369 |
-
|
370 |
-
// function isRectOverlapping(rect1, rect2) { //μ΄μ μ μ
|
371 |
-
// return !(rect1.right < rect2.left || rect1.left > rect2.right ||
|
372 |
-
// rect1.bottom < rect2.top || rect1.top > rect2.bottom);
|
373 |
-
// }
|
374 |
-
|
375 |
function checkSum() {
|
376 |
let sum = 0;
|
377 |
selectedApples.forEach(apple => sum += parseInt(apple.dataset.value));
|
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>π Apple Merge</title>
|
7 |
<style>
|
|
|
8 |
body {
|
9 |
font-family: 'SF Pro Text', 'SF Pro Icons', 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
|
10 |
display: flex;
|
|
|
63 |
}
|
64 |
|
65 |
.grid-cell {
|
66 |
+
width: 100%;
|
67 |
+
height: 100%;
|
68 |
box-sizing: border-box;
|
69 |
position: relative;
|
70 |
border-radius: 8px;
|
|
|
102 |
|
103 |
.apple span {
|
104 |
font-size: 0.5em;
|
105 |
+
color: #000;
|
106 |
font-weight: bold;
|
107 |
z-index: 3;
|
108 |
pointer-events: none;
|
|
|
111 |
top: 50%;
|
112 |
left: 50%;
|
113 |
transform: translate(-50%, -50%);
|
114 |
+
text-shadow: 0px 1px 3px #fff;
|
115 |
}
|
116 |
|
117 |
.apple.selected {
|
|
|
319 |
startCell = null;
|
320 |
event.preventDefault();
|
321 |
}
|
|
|
322 |
function selectApplesInBox() {
|
323 |
const boxRect = selectionBox.getBoundingClientRect();
|
324 |
+
const containerRect = gameContainer.getBoundingClientRect();
|
325 |
const apples = document.querySelectorAll('.apple');
|
326 |
|
327 |
+
// μ ν μμμ "μμͺ½" κ²½κ³ κ³μ° (margin μ μ©) - μ€μ¬μ κ²μ¬μ©
|
328 |
+
const selectionMargin = boxRect.width * 0.2; // marginμ μ μ§
|
329 |
+
const innerBoxLeft = boxRect.left - containerRect.left + selectionMargin;
|
330 |
+
const innerBoxTop = boxRect.top - containerRect.top + selectionMargin;
|
331 |
+
const innerBoxRight = boxRect.right - containerRect.left - selectionMargin;
|
332 |
+
const innerBoxBottom = boxRect.bottom - containerRect.top - selectionMargin;
|
333 |
|
334 |
apples.forEach(apple => {
|
335 |
const appleRect = apple.getBoundingClientRect();
|
|
|
338 |
const appleCenterX = appleRect.left + appleRect.width / 2 - containerRect.left;
|
339 |
const appleCenterY = appleRect.top + appleRect.height / 2 - containerRect.top;
|
340 |
|
341 |
+
// 1. μ€μ¬μ κΈ°λ° κ²μ¬ (μ격)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
const isInside = appleCenterX >= innerBoxLeft && appleCenterX <= innerBoxRight &&
|
343 |
+
appleCenterY >= innerBoxTop && appleCenterY <= innerBoxBottom;
|
344 |
+
|
345 |
+
// 2. κ²½κ³ κ²ΉμΉ¨ κ²μ¬ (μν) - containerRect κΈ°μ€ μλ μ’ν μ¬μ©
|
346 |
+
const adjustedBoxRect = {
|
347 |
+
left: boxRect.left - containerRect.left,
|
348 |
+
top: boxRect.top - containerRect.top,
|
349 |
+
right: boxRect.right - containerRect.left,
|
350 |
+
bottom: boxRect.bottom - containerRect.top
|
351 |
+
};
|
352 |
+
const adjustedAppleRect = {
|
353 |
+
left: appleRect.left - containerRect.left,
|
354 |
+
top: appleRect.top - containerRect.top,
|
355 |
+
right: appleRect.right - containerRect.left,
|
356 |
+
bottom: appleRect.bottom - containerRect.top
|
357 |
+
};
|
358 |
+
|
359 |
+
const isOverlapping = !(adjustedBoxRect.right < adjustedAppleRect.left ||
|
360 |
+
adjustedBoxRect.left > adjustedAppleRect.right ||
|
361 |
+
adjustedBoxRect.bottom < adjustedAppleRect.top ||
|
362 |
+
adjustedBoxRect.top > adjustedAppleRect.bottom);
|
363 |
+
|
364 |
+
|
365 |
+
// λ 쑰건 μ€ νλλΌλ λ§μ‘±νλ©΄ μ ν
|
366 |
+
if (isInside || isOverlapping) {
|
367 |
+
if (!selectedApples.includes(apple)) {
|
368 |
+
apple.classList.add('selected');
|
369 |
+
selectedApples.push(apple);
|
370 |
+
}
|
371 |
+
} else {
|
372 |
+
apple.classList.remove('selected');
|
373 |
+
selectedApples = selectedApples.filter(a => a !== apple);
|
374 |
}
|
|
|
|
|
|
|
|
|
375 |
});
|
376 |
+
}
|
|
|
377 |
function deselectAllApples() {
|
378 |
selectedApples.forEach(apple => apple.classList.remove('selected'));
|
379 |
selectedApples = [];
|
380 |
}
|
381 |
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
function checkSum() {
|
383 |
let sum = 0;
|
384 |
selectedApples.forEach(apple => sum += parseInt(apple.dataset.value));
|