Add 2 files
Browse files- README.md +7 -5
- index.html +494 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: test
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,494 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Ball Sort Puzzle</title>
|
| 7 |
+
<style>
|
| 8 |
+
* {
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 0;
|
| 11 |
+
box-sizing: border-box;
|
| 12 |
+
font-family: 'Arial', sans-serif;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
body {
|
| 16 |
+
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
|
| 17 |
+
height: 100vh;
|
| 18 |
+
display: flex;
|
| 19 |
+
flex-direction: column;
|
| 20 |
+
align-items: center;
|
| 21 |
+
justify-content: center;
|
| 22 |
+
color: white;
|
| 23 |
+
overflow: hidden;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
.game-container {
|
| 27 |
+
display: flex;
|
| 28 |
+
flex-direction: column;
|
| 29 |
+
align-items: center;
|
| 30 |
+
width: 100%;
|
| 31 |
+
max-width: 800px;
|
| 32 |
+
padding: 20px;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
h1 {
|
| 36 |
+
margin-bottom: 20px;
|
| 37 |
+
font-size: 2.5rem;
|
| 38 |
+
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
|
| 39 |
+
text-align: center;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
.tubes-container {
|
| 43 |
+
display: flex;
|
| 44 |
+
flex-wrap: wrap;
|
| 45 |
+
justify-content: center;
|
| 46 |
+
gap: 20px;
|
| 47 |
+
width: 100%;
|
| 48 |
+
margin: 30px 0;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.tube {
|
| 52 |
+
width: 60px;
|
| 53 |
+
height: 200px;
|
| 54 |
+
background-color: rgba(255, 255, 255, 0.1);
|
| 55 |
+
border-radius: 5px 5px 0 0;
|
| 56 |
+
position: relative;
|
| 57 |
+
cursor: pointer;
|
| 58 |
+
border: 2px solid rgba(255, 255, 255, 0.3);
|
| 59 |
+
display: flex;
|
| 60 |
+
flex-direction: column-reverse;
|
| 61 |
+
align-items: center;
|
| 62 |
+
transition: transform 0.2s;
|
| 63 |
+
margin-bottom: 40px;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.tube::after {
|
| 67 |
+
content: '';
|
| 68 |
+
position: absolute;
|
| 69 |
+
bottom: -20px;
|
| 70 |
+
left: -2px;
|
| 71 |
+
right: -2px;
|
| 72 |
+
height: 20px;
|
| 73 |
+
background-color: rgba(255, 255, 255, 0.1);
|
| 74 |
+
border-radius: 0 0 5px 5px;
|
| 75 |
+
border: 2px solid rgba(255, 255, 255, 0.3);
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
.tube:hover {
|
| 79 |
+
transform: translateY(-5px);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.tube.selected {
|
| 83 |
+
transform: scale(1.05);
|
| 84 |
+
box-shadow: 0 0 15px rgba(255, 255, 255, 0.7);
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.ball {
|
| 88 |
+
width: 50px;
|
| 89 |
+
height: 50px;
|
| 90 |
+
border-radius: 50%;
|
| 91 |
+
margin-top: 5px;
|
| 92 |
+
transition: all 0.3s ease;
|
| 93 |
+
position: relative;
|
| 94 |
+
display: flex;
|
| 95 |
+
align-items: center;
|
| 96 |
+
justify-content: center;
|
| 97 |
+
font-weight: bold;
|
| 98 |
+
color: rgba(0, 0, 0, 0.5);
|
| 99 |
+
box-shadow: inset -5px -5px 10px rgba(0, 0, 0, 0.2);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.ball::after {
|
| 103 |
+
content: '';
|
| 104 |
+
position: absolute;
|
| 105 |
+
top: 10px;
|
| 106 |
+
left: 10px;
|
| 107 |
+
width: 15px;
|
| 108 |
+
height: 15px;
|
| 109 |
+
border-radius: 50%;
|
| 110 |
+
background-color: rgba(255, 255, 255, 0.4);
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
.controls {
|
| 114 |
+
display: flex;
|
| 115 |
+
gap: 20px;
|
| 116 |
+
margin-top: 20px;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
button {
|
| 120 |
+
padding: 10px 20px;
|
| 121 |
+
font-size: 1rem;
|
| 122 |
+
background-color: rgba(255, 255, 255, 0.2);
|
| 123 |
+
color: white;
|
| 124 |
+
border: 2px solid white;
|
| 125 |
+
border-radius: 5px;
|
| 126 |
+
cursor: pointer;
|
| 127 |
+
transition: all 0.3s;
|
| 128 |
+
text-transform: uppercase;
|
| 129 |
+
letter-spacing: 1px;
|
| 130 |
+
font-weight: bold;
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
button:hover {
|
| 134 |
+
background-color: rgba(255, 255, 255, 0.4);
|
| 135 |
+
transform: translateY(-2px);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.level-info {
|
| 139 |
+
margin-top: 20px;
|
| 140 |
+
font-size: 1.2rem;
|
| 141 |
+
text-align: center;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.message {
|
| 145 |
+
position: fixed;
|
| 146 |
+
top: 50%;
|
| 147 |
+
left: 50%;
|
| 148 |
+
transform: translate(-50%, -50%);
|
| 149 |
+
background-color: rgba(0, 0, 0, 0.8);
|
| 150 |
+
color: white;
|
| 151 |
+
padding: 30px 50px;
|
| 152 |
+
border-radius: 10px;
|
| 153 |
+
font-size: 2rem;
|
| 154 |
+
display: none;
|
| 155 |
+
z-index: 100;
|
| 156 |
+
text-align: center;
|
| 157 |
+
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
.message button {
|
| 161 |
+
margin-top: 20px;
|
| 162 |
+
display: block;
|
| 163 |
+
width: 100%;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
.move-counter {
|
| 167 |
+
font-size: 1.2rem;
|
| 168 |
+
margin-bottom: 20px;
|
| 169 |
+
background-color: rgba(0, 0, 0, 0.3);
|
| 170 |
+
padding: 10px 20px;
|
| 171 |
+
border-radius: 5px;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
@media (max-width: 600px) {
|
| 175 |
+
.tube {
|
| 176 |
+
width: 50px;
|
| 177 |
+
height: 180px;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.ball {
|
| 181 |
+
width: 45px;
|
| 182 |
+
height: 45px;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
h1 {
|
| 186 |
+
font-size: 1.8rem;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.floating-balls {
|
| 191 |
+
position: absolute;
|
| 192 |
+
top: 0;
|
| 193 |
+
left: 0;
|
| 194 |
+
width: 100%;
|
| 195 |
+
height: 100%;
|
| 196 |
+
pointer-events: none;
|
| 197 |
+
z-index: -1;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
.floating-ball {
|
| 201 |
+
position: absolute;
|
| 202 |
+
border-radius: 50%;
|
| 203 |
+
opacity: 0.3;
|
| 204 |
+
animation: float 15s infinite linear;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
@keyframes float {
|
| 208 |
+
0% {
|
| 209 |
+
transform: translate(0, 0) rotate(0deg);
|
| 210 |
+
}
|
| 211 |
+
25% {
|
| 212 |
+
transform: translate(100px, 50px) rotate(90deg);
|
| 213 |
+
}
|
| 214 |
+
50% {
|
| 215 |
+
transform: translate(200px, -50px) rotate(180deg);
|
| 216 |
+
}
|
| 217 |
+
75% {
|
| 218 |
+
transform: translate(100px, 50px) rotate(270deg);
|
| 219 |
+
}
|
| 220 |
+
100% {
|
| 221 |
+
transform: translate(0, 0) rotate(360deg);
|
| 222 |
+
}
|
| 223 |
+
}
|
| 224 |
+
</style>
|
| 225 |
+
</head>
|
| 226 |
+
<body>
|
| 227 |
+
<div class="floating-balls" id="floatingBalls"></div>
|
| 228 |
+
|
| 229 |
+
<div class="game-container">
|
| 230 |
+
<h1>Ball Sort Puzzle</h1>
|
| 231 |
+
<div class="move-counter">Moves: <span id="moves">0</span></div>
|
| 232 |
+
<div class="tubes-container" id="tubes"></div>
|
| 233 |
+
<div class="level-info">Level: <span id="level">1</span></div>
|
| 234 |
+
<div class="controls">
|
| 235 |
+
<button id="btnNewGame">New Game</button>
|
| 236 |
+
<button id="btnUndo">Undo</button>
|
| 237 |
+
</div>
|
| 238 |
+
</div>
|
| 239 |
+
|
| 240 |
+
<div class="message" id="winMessage">
|
| 241 |
+
Level Complete!
|
| 242 |
+
<button id="btnNextLevel">Next Level</button>
|
| 243 |
+
</div>
|
| 244 |
+
|
| 245 |
+
<script>
|
| 246 |
+
// Game state
|
| 247 |
+
const gameState = {
|
| 248 |
+
tubes: [],
|
| 249 |
+
selectedTube: null,
|
| 250 |
+
moves: 0,
|
| 251 |
+
level: 1,
|
| 252 |
+
moveHistory: []
|
| 253 |
+
};
|
| 254 |
+
|
| 255 |
+
// Colors
|
| 256 |
+
const colors = [
|
| 257 |
+
'#FF5252', '#FF4081', '#E040FB', '#7C4DFF',
|
| 258 |
+
'#536DFE', '#448AFF', '#40C4FF', '#18FFFF',
|
| 259 |
+
'#64FFDA', '#69F0AE', '#B2FF59', '#EEFF41',
|
| 260 |
+
'#FFFF00', '#FFD740', '#FFAB40', '#FF6E40'
|
| 261 |
+
];
|
| 262 |
+
|
| 263 |
+
// DOM elements
|
| 264 |
+
const tubesContainer = document.getElementById('tubes');
|
| 265 |
+
const movesDisplay = document.getElementById('moves');
|
| 266 |
+
const levelDisplay = document.getElementById('level');
|
| 267 |
+
const btnNewGame = document.getElementById('btnNewGame');
|
| 268 |
+
const btnUndo = document.getElementById('btnUndo');
|
| 269 |
+
const winMessage = document.getElementById('winMessage');
|
| 270 |
+
const btnNextLevel = document.getElementById('btnNextLevel');
|
| 271 |
+
const floatingBalls = document.getElementById('floatingBalls');
|
| 272 |
+
|
| 273 |
+
// Initialize floating background balls
|
| 274 |
+
function createFloatingBalls() {
|
| 275 |
+
floatingBalls.innerHTML = '';
|
| 276 |
+
for (let i = 0; i < 20; i++) {
|
| 277 |
+
const ball = document.createElement('div');
|
| 278 |
+
ball.className = 'floating-ball';
|
| 279 |
+
const size = Math.random() * 100 + 50;
|
| 280 |
+
ball.style.width = `${size}px`;
|
| 281 |
+
ball.style.height = `${size}px`;
|
| 282 |
+
ball.style.background = colors[Math.floor(Math.random() * colors.length)];
|
| 283 |
+
ball.style.left = `${Math.random() * 100}%`;
|
| 284 |
+
ball.style.top = `${Math.random() * 100}%`;
|
| 285 |
+
ball.style.animationDuration = `${Math.random() * 20 + 10}s`;
|
| 286 |
+
floatingBalls.appendChild(ball);
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
// Initialize game
|
| 291 |
+
function initGame() {
|
| 292 |
+
gameState.tubes = [];
|
| 293 |
+
gameState.selectedTube = null;
|
| 294 |
+
gameState.moves = 0;
|
| 295 |
+
gameState.moveHistory = [];
|
| 296 |
+
|
| 297 |
+
movesDisplay.textContent = gameState.moves;
|
| 298 |
+
levelDisplay.textContent = gameState.level;
|
| 299 |
+
|
| 300 |
+
tubesContainer.innerHTML = '';
|
| 301 |
+
const tubeCount = Math.min(3 + gameState.level, 8);
|
| 302 |
+
const colorCount = Math.min(tubeCount - 2, colors.length);
|
| 303 |
+
|
| 304 |
+
// Create color set
|
| 305 |
+
const selectedColors = colors.slice(0, colorCount);
|
| 306 |
+
const allBalls = [];
|
| 307 |
+
|
| 308 |
+
// Create 4 balls for each color
|
| 309 |
+
selectedColors.forEach(color => {
|
| 310 |
+
for (let i = 0; i < 4; i++) {
|
| 311 |
+
allBalls.push(color);
|
| 312 |
+
}
|
| 313 |
+
});
|
| 314 |
+
|
| 315 |
+
// Shuffle balls
|
| 316 |
+
shuffleArray(allBalls);
|
| 317 |
+
|
| 318 |
+
// Distribute balls to tubes (first tubeCount - 2 tubes)
|
| 319 |
+
const ballsPerTube = allBalls.length / (tubeCount - 2);
|
| 320 |
+
for (let i = 0; i < tubeCount - 2; i++) {
|
| 321 |
+
const tubeBalls = [];
|
| 322 |
+
for (let j = 0; j < ballsPerTube; j++) {
|
| 323 |
+
tubeBalls.push(allBalls[i * ballsPerTube + j]);
|
| 324 |
+
}
|
| 325 |
+
gameState.tubes.push(tubeBalls);
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
// Add empty tubes (2)
|
| 329 |
+
for (let i = 0; i < 2; i++) {
|
| 330 |
+
gameState.tubes.push([]);
|
| 331 |
+
}
|
| 332 |
+
|
| 333 |
+
renderTubes();
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
// Helper function to shuffle an array
|
| 337 |
+
function shuffleArray(array) {
|
| 338 |
+
for (let i = array.length - 1; i > 0; i--) {
|
| 339 |
+
const j = Math.floor(Math.random() * (i + 1));
|
| 340 |
+
[array[i], array[j]] = [array[j], array[i]];
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
// Render tubes and balls
|
| 345 |
+
function renderTubes() {
|
| 346 |
+
tubesContainer.innerHTML = '';
|
| 347 |
+
gameState.tubes.forEach((tubeBalls, index) => {
|
| 348 |
+
const tubeElement = document.createElement('div');
|
| 349 |
+
tubeElement.className = 'tube';
|
| 350 |
+
if (gameState.selectedTube === index) {
|
| 351 |
+
tubeElement.classList.add('selected');
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
tubeElement.addEventListener('click', () => handleTubeClick(index));
|
| 355 |
+
|
| 356 |
+
tubeBalls.forEach((ballColor, ballIndex) => {
|
| 357 |
+
const ballElement = document.createElement('div');
|
| 358 |
+
ballElement.className = 'ball';
|
| 359 |
+
ballElement.style.backgroundColor = ballColor;
|
| 360 |
+
tubeElement.appendChild(ballElement);
|
| 361 |
+
});
|
| 362 |
+
|
| 363 |
+
tubesContainer.appendChild(tubeElement);
|
| 364 |
+
});
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
// Handle tube click
|
| 368 |
+
function handleTubeClick(tubeIndex) {
|
| 369 |
+
if (gameState.selectedTube === null) {
|
| 370 |
+
// Select a tube if it has balls
|
| 371 |
+
if (gameState.tubes[tubeIndex].length > 0) {
|
| 372 |
+
gameState.selectedTube = tubeIndex;
|
| 373 |
+
renderTubes();
|
| 374 |
+
}
|
| 375 |
+
} else {
|
| 376 |
+
// Try to move ball from selected tube to clicked tube
|
| 377 |
+
if (gameState.selectedTube === tubeIndex) {
|
| 378 |
+
// Deselect if same tube clicked
|
| 379 |
+
gameState.selectedTube = null;
|
| 380 |
+
renderTubes();
|
| 381 |
+
} else {
|
| 382 |
+
moveBall(gameState.selectedTube, tubeIndex);
|
| 383 |
+
}
|
| 384 |
+
}
|
| 385 |
+
}
|
| 386 |
+
|
| 387 |
+
// Move ball from one tube to another
|
| 388 |
+
function moveBall(fromTubeIndex, toTubeIndex) {
|
| 389 |
+
const fromTube = gameState.tubes[fromTubeIndex];
|
| 390 |
+
const toTube = gameState.tubes[toTubeIndex];
|
| 391 |
+
|
| 392 |
+
if (fromTube.length === 0) {
|
| 393 |
+
gameState.selectedTube = null;
|
| 394 |
+
renderTubes();
|
| 395 |
+
return;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
// Check if move is valid
|
| 399 |
+
const topBallColor = fromTube[fromTube.length - 1];
|
| 400 |
+
|
| 401 |
+
// Can move if:
|
| 402 |
+
// 1. Destination tube is empty, OR
|
| 403 |
+
// 2. Destination tube's top ball is same color and has space
|
| 404 |
+
if (toTube.length === 0 ||
|
| 405 |
+
(toTube[toTube.length - 1] === topBallColor && toTube.length < 4)) {
|
| 406 |
+
|
| 407 |
+
// Store move in history
|
| 408 |
+
const prevState = JSON.parse(JSON.stringify(gameState.tubes));
|
| 409 |
+
gameState.moveHistory.push(prevState);
|
| 410 |
+
|
| 411 |
+
// Move the ball(s) of the same color from top
|
| 412 |
+
let ballsToMove = 0;
|
| 413 |
+
for (let i = fromTube.length - 1; i >= 0; i--) {
|
| 414 |
+
if (fromTube[i] === topBallColor && (toTube.length + ballsToMove) < 4) {
|
| 415 |
+
ballsToMove++;
|
| 416 |
+
} else {
|
| 417 |
+
break;
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
// Move the balls
|
| 422 |
+
const movedBalls = fromTube.splice(fromTube.length - ballsToMove, ballsToMove);
|
| 423 |
+
toTube.push(...movedBalls);
|
| 424 |
+
|
| 425 |
+
gameState.moves++;
|
| 426 |
+
movesDisplay.textContent = gameState.moves;
|
| 427 |
+
|
| 428 |
+
// Check for win condition
|
| 429 |
+
if (checkWin()) {
|
| 430 |
+
showWinMessage();
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
gameState.selectedTube = null;
|
| 434 |
+
renderTubes();
|
| 435 |
+
} else {
|
| 436 |
+
gameState.selectedTube = null;
|
| 437 |
+
renderTubes();
|
| 438 |
+
}
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
// Check if all tubes are complete (all balls of same color or empty)
|
| 442 |
+
function checkWin() {
|
| 443 |
+
return gameState.tubes.every(tube => {
|
| 444 |
+
if (tube.length === 0) return true;
|
| 445 |
+
if (tube.length < 4) return false;
|
| 446 |
+
const firstColor = tube[0];
|
| 447 |
+
return tube.every(ball => ball === firstColor);
|
| 448 |
+
});
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
// Show win message
|
| 452 |
+
function showWinMessage() {
|
| 453 |
+
winMessage.style.display = 'block';
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
// Undo last move
|
| 457 |
+
function undoMove() {
|
| 458 |
+
if (gameState.moveHistory.length > 0) {
|
| 459 |
+
gameState.tubes = gameState.moveHistory.pop();
|
| 460 |
+
gameState.moves++;
|
| 461 |
+
movesDisplay.textContent = gameState.moves;
|
| 462 |
+
gameState.selectedTube = null;
|
| 463 |
+
renderTubes();
|
| 464 |
+
}
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
// Next level
|
| 468 |
+
function nextLevel() {
|
| 469 |
+
gameState.level++;
|
| 470 |
+
winMessage.style.display = 'none';
|
| 471 |
+
initGame();
|
| 472 |
+
}
|
| 473 |
+
|
| 474 |
+
// Event listeners
|
| 475 |
+
btnNewGame.addEventListener('click', initGame);
|
| 476 |
+
btnUndo.addEventListener('click', undoMove);
|
| 477 |
+
btnNextLevel.addEventListener('click', nextLevel);
|
| 478 |
+
|
| 479 |
+
// Initialize
|
| 480 |
+
createFloatingBalls();
|
| 481 |
+
initGame();
|
| 482 |
+
|
| 483 |
+
// Add keyboard controls
|
| 484 |
+
document.addEventListener('keydown', (e) => {
|
| 485 |
+
if (e.key === 'Escape') {
|
| 486 |
+
gameState.selectedTube = null;
|
| 487 |
+
renderTubes();
|
| 488 |
+
} else if (e.key === 'z' && (e.ctrlKey || e.metaKey)) {
|
| 489 |
+
undoMove();
|
| 490 |
+
}
|
| 491 |
+
});
|
| 492 |
+
</script>
|
| 493 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <a href="https://enzostvs-deepsite.hf.space" style="color: #fff;" target="_blank" >DeepSite</a> <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;"></p></body>
|
| 494 |
+
</html>
|