kimhyunwoo commited on
Commit
13dfc7c
Β·
verified Β·
1 Parent(s): 3420d40

Update index.html

Browse files
Files changed (1) hide show
  1. 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: #fff;
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: 3px 3px 0px black;
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(); // μ»¨ν…Œμ΄λ„ˆ rect
327
  const apples = document.querySelectorAll('.apple');
328
 
329
- // 좔가적인 μ•ˆμ „ 거리 (margin) - 더 쒁게 μ„ νƒλ˜λ„λ‘
330
- const selectionMargin = boxRect.width * 0.2; // 예: 선택 μ˜μ—­ λ„ˆλΉ„μ˜ 20%
 
 
 
 
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
- appleCenterY >= innerBoxTop && appleCenterY <= innerBoxBottom;
350
-
351
-
352
- if (isInside) {
353
- if (!selectedApples.includes(apple)) {
354
- apple.classList.add('selected');
355
- selectedApples.push(apple);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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));