create-template-html-css 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/COMPONENTS-GALLERY.html +124 -11
- package/README.md +6 -2
- package/bin/cli.js +8 -2
- package/demo-games/guess-number/index.html +71 -0
- package/demo-games/guess-number/script.js +216 -0
- package/demo-games/guess-number/style.css +337 -0
- package/demo-games/memory-game/index.html +50 -0
- package/demo-games/memory-game/script.js +216 -0
- package/demo-games/memory-game/style.css +288 -0
- package/demo-games/snake-game/index.html +61 -0
- package/demo-games/snake-game/script.js +360 -0
- package/demo-games/snake-game/style.css +246 -0
- package/demo-games/tic-tac-toe/index.html +57 -0
- package/demo-games/tic-tac-toe/script.js +156 -0
- package/demo-games/tic-tac-toe/style.css +244 -0
- package/package.json +1 -1
- package/templates/guess-number/index.html +71 -0
- package/templates/guess-number/script.js +216 -0
- package/templates/guess-number/style.css +337 -0
- package/templates/memory-game/index.html +50 -0
- package/templates/memory-game/script.js +216 -0
- package/templates/memory-game/style.css +288 -0
- package/templates/snake-game/index.html +61 -0
- package/templates/snake-game/script.js +360 -0
- package/templates/snake-game/style.css +246 -0
- package/templates/tic-tac-toe/index.html +57 -0
- package/templates/tic-tac-toe/script.js +156 -0
- package/templates/tic-tac-toe/style.css +244 -0
package/COMPONENTS-GALLERY.html
CHANGED
|
@@ -436,6 +436,93 @@
|
|
|
436
436
|
<h2 class="color-schemes-title">🎨 Color Schemes Preview</h2>
|
|
437
437
|
<div class="schemes-grid" id="colorSchemesGrid"></div>
|
|
438
438
|
</div>
|
|
439
|
+
|
|
440
|
+
<!-- CLI Flags Section -->
|
|
441
|
+
<div class="color-schemes-section" style="margin-top: 40px;">
|
|
442
|
+
<h2 class="color-schemes-title">⚡ One-Command Creation (Non-Interactive)</h2>
|
|
443
|
+
<p style="text-align: center; color: #666; margin-bottom: 20px;">
|
|
444
|
+
Create components instantly with all flags in a single command - no prompts needed!<br>
|
|
445
|
+
<small>Install globally with npm, or use npx to run without installation</small>
|
|
446
|
+
</p>
|
|
447
|
+
|
|
448
|
+
<div style="max-width: 900px; margin: 0 auto;">
|
|
449
|
+
<!-- Available Flags -->
|
|
450
|
+
<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; margin-bottom: 20px;">
|
|
451
|
+
<h3 style="margin: 0 0 15px 0; color: #333;">📋 Available Flags:</h3>
|
|
452
|
+
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 15px;">
|
|
453
|
+
<div>
|
|
454
|
+
<code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px; color: #495057;">-c, --component <type></code>
|
|
455
|
+
<div style="font-size: 0.9rem; color: #666; margin-top: 5px;">Component type (required)</div>
|
|
456
|
+
</div>
|
|
457
|
+
<div>
|
|
458
|
+
<code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px; color: #495057;">-n, --name <name></code>
|
|
459
|
+
<div style="font-size: 0.9rem; color: #666; margin-top: 5px;">Project name (required)</div>
|
|
460
|
+
</div>
|
|
461
|
+
<div>
|
|
462
|
+
<code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px; color: #495057;">--dark-mode</code>
|
|
463
|
+
<div style="font-size: 0.9rem; color: #666; margin-top: 5px;">Add dark mode support</div>
|
|
464
|
+
</div>
|
|
465
|
+
<div>
|
|
466
|
+
<code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px; color: #495057;">--color-scheme <name></code>
|
|
467
|
+
<div style="font-size: 0.9rem; color: #666; margin-top: 5px;">Use preset colors</div>
|
|
468
|
+
</div>
|
|
469
|
+
<div>
|
|
470
|
+
<code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px; color: #495057;">--primary-color <hex></code>
|
|
471
|
+
<div style="font-size: 0.9rem; color: #666; margin-top: 5px;">Custom primary color</div>
|
|
472
|
+
</div>
|
|
473
|
+
<div>
|
|
474
|
+
<code style="background: #e9ecef; padding: 4px 8px; border-radius: 4px; color: #495057;">--secondary-color <hex></code>
|
|
475
|
+
<div style="font-size: 0.9rem; color: #666; margin-top: 5px;">Custom secondary color</div>
|
|
476
|
+
</div>
|
|
477
|
+
</div>
|
|
478
|
+
</div>
|
|
479
|
+
|
|
480
|
+
<!-- Installation Note -->
|
|
481
|
+
<div style="background: #fff3cd; border-left: 4px solid #ffc107; padding: 15px; border-radius: 4px; margin-bottom: 20px;">
|
|
482
|
+
<strong>📦 Installation:</strong>
|
|
483
|
+
<div style="margin-top: 8px;">
|
|
484
|
+
<code style="background: #fff; padding: 6px 12px; border-radius: 4px; display: inline-block; margin-right: 10px;">npm install -g create-template-html-css</code>
|
|
485
|
+
<span style="color: #666;">or use</span>
|
|
486
|
+
<code style="background: #fff; padding: 6px 12px; border-radius: 4px; display: inline-block; margin-left: 10px;">npx create-template-html-css</code>
|
|
487
|
+
</div>
|
|
488
|
+
</div>
|
|
489
|
+
|
|
490
|
+
<!-- Example Commands -->
|
|
491
|
+
<div style="background: #fff; border: 2px solid #e9ecef; border-radius: 8px; padding: 20px;">
|
|
492
|
+
<h3 style="margin: 0 0 15px 0; color: #333;">💡 Example Commands (After Installation):</h3>
|
|
493
|
+
|
|
494
|
+
<div class="code-block" style="margin: 15px 0;">
|
|
495
|
+
create-template create -c button -n my-button
|
|
496
|
+
<button class="copy-btn" onclick="copyExample(this)">Copy</button>
|
|
497
|
+
<div style="font-size: 0.85rem; color: #666; margin-top: 5px;">Basic: Create button with default colors</div>
|
|
498
|
+
</div>
|
|
499
|
+
|
|
500
|
+
<div class="code-block" style="margin: 15px 0;">
|
|
501
|
+
create-template create -c card -n my-card --color-scheme ocean
|
|
502
|
+
<button class="copy-btn" onclick="copyExample(this)">Copy</button>
|
|
503
|
+
<div style="font-size: 0.85rem; color: #666; margin-top: 5px;">With preset: Card with ocean color scheme</div>
|
|
504
|
+
</div>
|
|
505
|
+
|
|
506
|
+
<div class="code-block" style="margin: 15px 0;">
|
|
507
|
+
create-template create -c modal -n my-modal --dark-mode
|
|
508
|
+
<button class="copy-btn" onclick="copyExample(this)">Copy</button>
|
|
509
|
+
<div style="font-size: 0.85rem; color: #666; margin-top: 5px;">With dark mode: Modal with automatic dark theme</div>
|
|
510
|
+
</div>
|
|
511
|
+
|
|
512
|
+
<div class="code-block" style="margin: 15px 0;">
|
|
513
|
+
create-template create -c hero -n my-hero --primary-color "#FF5733" --secondary-color "#3498db"
|
|
514
|
+
<button class="copy-btn" onclick="copyExample(this)">Copy</button>
|
|
515
|
+
<div style="font-size: 0.85rem; color: #666; margin-top: 5px;">Custom colors: Hero with custom gradient</div>
|
|
516
|
+
</div>
|
|
517
|
+
|
|
518
|
+
<div class="code-block" style="margin: 15px 0;">
|
|
519
|
+
create-template create -c navigation -n my-nav --dark-mode --color-scheme sunset
|
|
520
|
+
<button class="copy-btn" onclick="copyExample(this)">Copy</button>
|
|
521
|
+
<div style="font-size: 0.85rem; color: #666; margin-top: 5px;">Everything: Navigation with dark mode + sunset colors</div>
|
|
522
|
+
</div>
|
|
523
|
+
</div>
|
|
524
|
+
</div>
|
|
525
|
+
</div>
|
|
439
526
|
</div>
|
|
440
527
|
|
|
441
528
|
<footer>
|
|
@@ -535,8 +622,8 @@
|
|
|
535
622
|
<div style="margin: 4px 0;">Secondary: ${scheme.secondary}</div>
|
|
536
623
|
</div>
|
|
537
624
|
<div style="display: flex; gap: 8px; margin-top: 12px;">
|
|
538
|
-
<button class="copy-btn" onclick="copySchemeCommand('
|
|
539
|
-
Copy
|
|
625
|
+
<button class="copy-btn" onclick="copySchemeCommand('global', '${key}')" style="flex: 1; font-size: 0.85rem;">
|
|
626
|
+
Copy command
|
|
540
627
|
</button>
|
|
541
628
|
<button class="copy-btn" onclick="copySchemeCommand('local', '${key}')" style="flex: 1; font-size: 0.85rem; opacity: 0.7;">
|
|
542
629
|
Copy local
|
|
@@ -550,14 +637,22 @@
|
|
|
550
637
|
// Copy color scheme command
|
|
551
638
|
function copySchemeCommand(mode, schemeKey) {
|
|
552
639
|
let text;
|
|
553
|
-
if (mode === '
|
|
554
|
-
text = `
|
|
640
|
+
if (mode === 'global') {
|
|
641
|
+
text = `create-template create -c button -n my-button --color-scheme ${schemeKey}`;
|
|
555
642
|
} else {
|
|
556
643
|
text = `npm run create -- -c button -n my-button --color-scheme ${schemeKey}`;
|
|
557
644
|
}
|
|
558
645
|
navigator.clipboard.writeText(text);
|
|
559
646
|
event.target.textContent = "✓ Copied!";
|
|
560
|
-
setTimeout(() => (event.target.textContent =
|
|
647
|
+
setTimeout(() => (event.target.textContent = mode === 'global' ? 'Copy command' : 'Copy local'), 2000);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Copy example command
|
|
651
|
+
function copyExample(btn) {
|
|
652
|
+
const text = btn.parentElement.textContent.trim().split("\n")[0].trim();
|
|
653
|
+
navigator.clipboard.writeText(text);
|
|
654
|
+
btn.textContent = "✓ Copied!";
|
|
655
|
+
setTimeout(() => (btn.textContent = "Copy"), 2000);
|
|
561
656
|
}
|
|
562
657
|
|
|
563
658
|
const components = [
|
|
@@ -616,14 +711,32 @@
|
|
|
616
711
|
<span class="category-badge">${c.cat.toUpperCase()}</span>
|
|
617
712
|
<p class="description">${c.desc}</p>
|
|
618
713
|
<ul class="features-list">${c.feat.map((f) => `<li>${f}</li>`).join("")}</ul>
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
714
|
+
|
|
715
|
+
<!-- Full Command Examples -->
|
|
716
|
+
<div style="margin-top: 15px; padding: 10px; background: #f8f9fa; border-radius: 6px;">
|
|
717
|
+
<div style="font-size: 0.85rem; font-weight: 600; color: #495057; margin-bottom: 8px;">📋 One-Command Examples:</div>
|
|
718
|
+
|
|
719
|
+
<div class="code-block" style="margin: 6px 0; font-size: 0.85rem;">
|
|
720
|
+
create-template create -c ${c.id} -n my-${c.id}
|
|
721
|
+
<button class="copy-btn" onclick="copy(this)" style="font-size: 0.75rem;">Copy</button>
|
|
623
722
|
</div>
|
|
624
|
-
|
|
723
|
+
|
|
724
|
+
<div class="code-block" style="margin: 6px 0; font-size: 0.85rem;">
|
|
725
|
+
create-template create -c ${c.id} -n my-${c.id} --color-scheme ocean
|
|
726
|
+
<button class="copy-btn" onclick="copy(this)" style="font-size: 0.75rem;">Copy</button>
|
|
727
|
+
</div>
|
|
728
|
+
|
|
729
|
+
<div class="code-block" style="margin: 6px 0; font-size: 0.85rem;">
|
|
730
|
+
create-template create -c ${c.id} -n my-${c.id} --dark-mode --color-scheme sunset
|
|
731
|
+
<button class="copy-btn" onclick="copy(this)" style="font-size: 0.75rem;">Copy</button>
|
|
732
|
+
</div>
|
|
733
|
+
</div>
|
|
734
|
+
|
|
735
|
+
<!-- Local npm command -->
|
|
736
|
+
<div style="display: flex; gap: 10px; margin-top: 12px;">
|
|
737
|
+
<div class="code-block" style="flex: 1; opacity: 0.6; font-size: 0.85rem;">
|
|
625
738
|
npm run create -- -c ${c.id}
|
|
626
|
-
<button class="copy-btn" onclick="copy(this)">
|
|
739
|
+
<button class="copy-btn" onclick="copy(this)" style="font-size: 0.75rem;">Local</button>
|
|
627
740
|
</div>
|
|
628
741
|
</div>
|
|
629
742
|
</div>
|
package/README.md
CHANGED
|
@@ -113,9 +113,13 @@ New **COMPONENTS-GALLERY.html** showcase page:
|
|
|
113
113
|
|
|
114
114
|
**Open gallery:**
|
|
115
115
|
```bash
|
|
116
|
+
# After global install
|
|
117
|
+
create-template gallery
|
|
118
|
+
|
|
119
|
+
# Or run directly with npx (first install package)
|
|
120
|
+
npx create-template-html-css
|
|
121
|
+
# Then run:
|
|
116
122
|
create-template gallery
|
|
117
|
-
# or
|
|
118
|
-
npx create-template gallery
|
|
119
123
|
```
|
|
120
124
|
|
|
121
125
|
### 📚 Enhanced Documentation
|
package/bin/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ program
|
|
|
14
14
|
.description(
|
|
15
15
|
chalk.cyan("🎨 Create HTML/CSS UI component templates in seconds"),
|
|
16
16
|
)
|
|
17
|
-
.version("1.8.
|
|
17
|
+
.version("1.8.1");
|
|
18
18
|
|
|
19
19
|
// Add intro message
|
|
20
20
|
program.on("--help", () => {
|
|
@@ -601,7 +601,7 @@ program
|
|
|
601
601
|
.command("list")
|
|
602
602
|
.description(chalk.green("List all available templates"))
|
|
603
603
|
.action(() => {
|
|
604
|
-
console.log("\n" + chalk.blue("📦 Available Components (
|
|
604
|
+
console.log("\n" + chalk.blue("📦 Available Components (30 total)\n"));
|
|
605
605
|
|
|
606
606
|
console.log(chalk.yellow("━ Basic Components (9)"));
|
|
607
607
|
console.log(" button Styled button component");
|
|
@@ -643,6 +643,12 @@ program
|
|
|
643
643
|
console.log(" accordion Collapsible accordion component");
|
|
644
644
|
console.log(" tabs Tabbed content switcher");
|
|
645
645
|
|
|
646
|
+
console.log("\n" + chalk.green("━ Interactive Games (4)"));
|
|
647
|
+
console.log(" tic-tac-toe Classic Tic-Tac-Toe game with score tracking");
|
|
648
|
+
console.log(" memory-game Memory card matching game with difficulty levels");
|
|
649
|
+
console.log(" snake-game Classic Snake game with keyboard controls");
|
|
650
|
+
console.log(" guess-number Number guessing game with hints and scoring");
|
|
651
|
+
|
|
646
652
|
console.log("\n" + chalk.gray("Usage:"));
|
|
647
653
|
console.log(" create-template create Create a new component");
|
|
648
654
|
console.log(" create-template insert Insert into HTML file");
|
|
@@ -0,0 +1,71 @@
|
|
|
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>{{name}} - Guess Number</title>
|
|
7
|
+
<link rel="stylesheet" href="style.css">
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div class="container">
|
|
11
|
+
<div class="game-card">
|
|
12
|
+
<h1>🎯 Guess the Number</h1>
|
|
13
|
+
|
|
14
|
+
<div class="game-info">
|
|
15
|
+
<div class="info-row">
|
|
16
|
+
<span class="label">Range:</span>
|
|
17
|
+
<span id="rangeDisplay" class="value">1 - 100</span>
|
|
18
|
+
</div>
|
|
19
|
+
<div class="info-row">
|
|
20
|
+
<span class="label">Attempts:</span>
|
|
21
|
+
<span id="attempts" class="value">0</span>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="info-row">
|
|
24
|
+
<span class="label">Best Score:</span>
|
|
25
|
+
<span id="bestScore" class="value">-</span>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<div class="hint-section">
|
|
30
|
+
<div class="hint-box" id="hintBox">
|
|
31
|
+
<p id="hintText">I'm thinking of a number...</p>
|
|
32
|
+
<p id="hintDetails">Make your first guess!</p>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div class="input-section">
|
|
37
|
+
<input
|
|
38
|
+
type="number"
|
|
39
|
+
id="guessInput"
|
|
40
|
+
placeholder="Enter your guess"
|
|
41
|
+
min="1"
|
|
42
|
+
max="100"
|
|
43
|
+
/>
|
|
44
|
+
<button id="guessBtn" class="btn btn-primary">Guess</button>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div class="history-section">
|
|
48
|
+
<h3>Previous Guesses</h3>
|
|
49
|
+
<div id="guessHistory" class="guess-history">
|
|
50
|
+
<p class="empty-state">No guesses yet</p>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div class="difficulty-section">
|
|
55
|
+
<h3>Difficulty</h3>
|
|
56
|
+
<div class="difficulty-buttons">
|
|
57
|
+
<button class="difficulty-btn active" data-range="100">Easy (1-100)</button>
|
|
58
|
+
<button class="difficulty-btn" data-range="500">Medium (1-500)</button>
|
|
59
|
+
<button class="difficulty-btn" data-range="1000">Hard (1-1000)</button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div class="button-group">
|
|
64
|
+
<button id="newGameBtn" class="btn btn-success">New Game</button>
|
|
65
|
+
<button id="giveUpBtn" class="btn btn-secondary">Give Up</button>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
<script src="script.js"></script>
|
|
70
|
+
</body>
|
|
71
|
+
</html>
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// Guess the Number Game Logic
|
|
2
|
+
|
|
3
|
+
const guessInput = document.getElementById('guessInput');
|
|
4
|
+
const guessBtn = document.getElementById('guessBtn');
|
|
5
|
+
const newGameBtn = document.getElementById('newGameBtn');
|
|
6
|
+
const giveUpBtn = document.getElementById('giveUpBtn');
|
|
7
|
+
const attemptsDisplay = document.getElementById('attempts');
|
|
8
|
+
const bestScoreDisplay = document.getElementById('bestScore');
|
|
9
|
+
const rangeDisplay = document.getElementById('rangeDisplay');
|
|
10
|
+
const hintBox = document.getElementById('hintBox');
|
|
11
|
+
const hintText = document.getElementById('hintText');
|
|
12
|
+
const hintDetails = document.getElementById('hintDetails');
|
|
13
|
+
const guessHistory = document.getElementById('guessHistory');
|
|
14
|
+
const difficultyBtns = document.querySelectorAll('.difficulty-btn');
|
|
15
|
+
|
|
16
|
+
let targetNumber = 0;
|
|
17
|
+
let attempts = 0;
|
|
18
|
+
let maxRange = 100;
|
|
19
|
+
let guesses = [];
|
|
20
|
+
let bestScores = {
|
|
21
|
+
100: localStorage.getItem('bestScore100') || null,
|
|
22
|
+
500: localStorage.getItem('bestScore500') || null,
|
|
23
|
+
1000: localStorage.getItem('bestScore1000') || null
|
|
24
|
+
};
|
|
25
|
+
let gameActive = true;
|
|
26
|
+
|
|
27
|
+
// Initialize game
|
|
28
|
+
function initGame() {
|
|
29
|
+
targetNumber = Math.floor(Math.random() * maxRange) + 1;
|
|
30
|
+
attempts = 0;
|
|
31
|
+
guesses = [];
|
|
32
|
+
gameActive = true;
|
|
33
|
+
|
|
34
|
+
updateDisplay();
|
|
35
|
+
guessInput.value = '';
|
|
36
|
+
guessInput.disabled = false;
|
|
37
|
+
guessBtn.disabled = false;
|
|
38
|
+
guessInput.focus();
|
|
39
|
+
|
|
40
|
+
hintBox.className = 'hint-box';
|
|
41
|
+
hintText.textContent = "I'm thinking of a number...";
|
|
42
|
+
hintDetails.textContent = 'Make your first guess!';
|
|
43
|
+
|
|
44
|
+
guessHistory.innerHTML = '<p class="empty-state">No guesses yet</p>';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Make a guess
|
|
48
|
+
function makeGuess() {
|
|
49
|
+
if (!gameActive) return;
|
|
50
|
+
|
|
51
|
+
const guess = parseInt(guessInput.value);
|
|
52
|
+
|
|
53
|
+
// Validate input
|
|
54
|
+
if (isNaN(guess) || guess < 1 || guess > maxRange) {
|
|
55
|
+
showHint('invalid', '⚠️ Invalid Input', `Please enter a number between 1 and ${maxRange}`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Check if already guessed
|
|
60
|
+
if (guesses.includes(guess)) {
|
|
61
|
+
showHint('duplicate', '🔄 Already Guessed', 'You already tried this number!');
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
attempts++;
|
|
66
|
+
guesses.push(guess);
|
|
67
|
+
updateDisplay();
|
|
68
|
+
addToHistory(guess);
|
|
69
|
+
|
|
70
|
+
// Check if correct
|
|
71
|
+
if (guess === targetNumber) {
|
|
72
|
+
handleWin();
|
|
73
|
+
} else if (guess < targetNumber) {
|
|
74
|
+
const diff = targetNumber - guess;
|
|
75
|
+
if (diff <= 5) {
|
|
76
|
+
showHint('hot', '🔥 Very Hot!', 'You\'re super close! Go higher!');
|
|
77
|
+
} else if (diff <= 10) {
|
|
78
|
+
showHint('warm', '🌡️ Hot!', 'Getting closer! Go higher!');
|
|
79
|
+
} else if (diff <= 20) {
|
|
80
|
+
showHint('cool', '❄️ Warm', 'Go higher!');
|
|
81
|
+
} else {
|
|
82
|
+
showHint('cold', '🧊 Cold', 'Too low! Go much higher!');
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
const diff = guess - targetNumber;
|
|
86
|
+
if (diff <= 5) {
|
|
87
|
+
showHint('hot', '🔥 Very Hot!', 'You\'re super close! Go lower!');
|
|
88
|
+
} else if (diff <= 10) {
|
|
89
|
+
showHint('warm', '🌡️ Hot!', 'Getting closer! Go lower!');
|
|
90
|
+
} else if (diff <= 20) {
|
|
91
|
+
showHint('cool', '❄️ Warm', 'Go lower!');
|
|
92
|
+
} else {
|
|
93
|
+
showHint('cold', '🧊 Cold', 'Too high! Go much lower!');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
guessInput.value = '';
|
|
98
|
+
guessInput.focus();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Handle win
|
|
102
|
+
function handleWin() {
|
|
103
|
+
gameActive = false;
|
|
104
|
+
guessInput.disabled = true;
|
|
105
|
+
guessBtn.disabled = true;
|
|
106
|
+
|
|
107
|
+
showHint('win', '🎉 Congratulations!', `You found it in ${attempts} attempts!`);
|
|
108
|
+
|
|
109
|
+
// Update best score
|
|
110
|
+
if (!bestScores[maxRange] || attempts < bestScores[maxRange]) {
|
|
111
|
+
bestScores[maxRange] = attempts;
|
|
112
|
+
localStorage.setItem(`bestScore${maxRange}`, attempts);
|
|
113
|
+
bestScoreDisplay.textContent = attempts;
|
|
114
|
+
|
|
115
|
+
// Show new record message
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
hintDetails.textContent = `🏆 New Record: ${attempts} attempts!`;
|
|
118
|
+
}, 1500);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Give up
|
|
123
|
+
function giveUp() {
|
|
124
|
+
if (!gameActive) return;
|
|
125
|
+
|
|
126
|
+
gameActive = false;
|
|
127
|
+
guessInput.disabled = true;
|
|
128
|
+
guessBtn.disabled = true;
|
|
129
|
+
|
|
130
|
+
showHint('give-up', '😔 Game Over', `The number was ${targetNumber}`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Show hint
|
|
134
|
+
function showHint(type, title, details) {
|
|
135
|
+
hintBox.className = `hint-box ${type}`;
|
|
136
|
+
hintText.textContent = title;
|
|
137
|
+
hintDetails.textContent = details;
|
|
138
|
+
|
|
139
|
+
// Animate
|
|
140
|
+
hintBox.style.animation = 'none';
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
hintBox.style.animation = 'bounceIn 0.5s ease';
|
|
143
|
+
}, 10);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Add to history
|
|
147
|
+
function addToHistory(guess) {
|
|
148
|
+
if (guesses.length === 1) {
|
|
149
|
+
guessHistory.innerHTML = '';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const guessItem = document.createElement('div');
|
|
153
|
+
guessItem.className = 'guess-item';
|
|
154
|
+
|
|
155
|
+
let icon = '';
|
|
156
|
+
if (guess === targetNumber) {
|
|
157
|
+
icon = '🎯';
|
|
158
|
+
guessItem.classList.add('correct');
|
|
159
|
+
} else if (Math.abs(guess - targetNumber) <= 5) {
|
|
160
|
+
icon = '🔥';
|
|
161
|
+
} else if (Math.abs(guess - targetNumber) <= 10) {
|
|
162
|
+
icon = '🌡️';
|
|
163
|
+
} else if (Math.abs(guess - targetNumber) <= 20) {
|
|
164
|
+
icon = '❄️';
|
|
165
|
+
} else {
|
|
166
|
+
icon = '🧊';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
guessItem.innerHTML = `
|
|
170
|
+
<span class="guess-number">${guess}</span>
|
|
171
|
+
<span class="guess-icon">${icon}</span>
|
|
172
|
+
`;
|
|
173
|
+
|
|
174
|
+
guessHistory.prepend(guessItem);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Update display
|
|
178
|
+
function updateDisplay() {
|
|
179
|
+
attemptsDisplay.textContent = attempts;
|
|
180
|
+
bestScoreDisplay.textContent = bestScores[maxRange] || '-';
|
|
181
|
+
rangeDisplay.textContent = `1 - ${maxRange}`;
|
|
182
|
+
guessInput.setAttribute('max', maxRange);
|
|
183
|
+
guessInput.setAttribute('placeholder', `Enter number (1-${maxRange})`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Change difficulty
|
|
187
|
+
function changeDifficulty(newRange) {
|
|
188
|
+
maxRange = parseInt(newRange);
|
|
189
|
+
|
|
190
|
+
// Update active button
|
|
191
|
+
difficultyBtns.forEach(btn => {
|
|
192
|
+
btn.classList.toggle('active', parseInt(btn.dataset.range) === maxRange);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
initGame();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Event listeners
|
|
199
|
+
guessBtn.addEventListener('click', makeGuess);
|
|
200
|
+
newGameBtn.addEventListener('click', initGame);
|
|
201
|
+
giveUpBtn.addEventListener('click', giveUp);
|
|
202
|
+
|
|
203
|
+
guessInput.addEventListener('keypress', (e) => {
|
|
204
|
+
if (e.key === 'Enter') {
|
|
205
|
+
makeGuess();
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
difficultyBtns.forEach(btn => {
|
|
210
|
+
btn.addEventListener('click', () => {
|
|
211
|
+
changeDifficulty(btn.dataset.range);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Initialize on load
|
|
216
|
+
initGame();
|