Skip to content

Commit

Permalink
const minDistance -> let minDistance
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinqwq committed Nov 12, 2024
1 parent 4b64a17 commit 1eaab0f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 5 additions & 4 deletions scripts/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ class CatGame {
generateNonOverlappingPositions() {
const positions = [];
const catSize = Math.min(80, window.innerWidth * 0.15);
const minDistance = catSize * 1.2;
let minDistance = catSize * 1.2;
const padding = 20;
const maxAttempts = 100;

for (let i = 0; i < this.totalCats; i++) {
let newPosition;
let overlap;
let attempts = 0;
let currentMinDistance = minDistance;

do {
overlap = false;
Expand All @@ -164,18 +165,18 @@ class CatGame {
Math.pow(newPosition.x - pos.x, 2) +
Math.pow(newPosition.y - pos.y, 2)
);
if (distance < minDistance) {
if (distance < currentMinDistance) {
overlap = true;
break;
}
}

attempts++;
if (attempts > maxAttempts) {
minDistance *= 0.9;
currentMinDistance *= 0.9;
attempts = 0;
}
} while (overlap);
} while (overlap && currentMinDistance > catSize * 0.5);

positions.push(newPosition);
}
Expand Down
22 changes: 22 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,39 @@
padding: 30px 50px;
border-radius: 15px;
box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
display: flex;
flex-direction: column;
align-items: center;
}

.start-message h1 {
color: #c41e3a;
margin-bottom: 20px;
width: 100%;
}

.start-message p {
color: #2C3E50;
font-size: 20px;
margin: 10px 0;
width: 100%;
}

#start-game-btn {
margin-top: 30px;
font-size: 24px;
padding: 15px 40px;
background: #c41e3a;
border: none;
border-radius: 25px;
color: white;
cursor: pointer;
transition: all 0.3s ease;
}

#start-game-btn:hover {
transform: scale(1.1);
box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

/* 添加新的响应式样式 */
Expand Down

0 comments on commit 1eaab0f

Please sign in to comment.