Files
guess-number/index.html
2025-09-09 13:03:21 +03:00

333 lines
10 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🎯 Number Guessing Game</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
padding: 30px;
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
max-width: 800px;
width: 100%;
text-align: center;
}
h1 {
color: #333;
margin-bottom: 20px;
font-size: 2.5em;
}
.instructions {
background: #f8f9fa;
padding: 20px;
border-radius: 15px;
margin-bottom: 30px;
color: #555;
line-height: 1.6;
}
.game-section {
display: none;
}
.game-section.active {
display: block;
}
.group-container {
background: #fff;
border: 2px solid #e9ecef;
border-radius: 15px;
padding: 25px;
margin: 20px 0;
}
.group-title {
font-size: 1.5em;
color: #495057;
margin-bottom: 15px;
font-weight: bold;
}
.numbers-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
gap: 10px;
margin: 20px 0;
padding: 20px;
background: #f8f9fa;
border-radius: 10px;
}
.number-item {
background: linear-gradient(45deg, #4CAF50, #45a049);
color: white;
padding: 10px;
border-radius: 8px;
font-weight: bold;
font-size: 1.1em;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
transition: transform 0.2s;
}
.number-item:hover {
transform: scale(1.05);
}
.buttons {
display: flex;
gap: 20px;
justify-content: center;
margin-top: 25px;
}
.btn {
padding: 15px 30px;
border: none;
border-radius: 10px;
font-size: 1.2em;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
min-width: 120px;
}
.btn-yes {
background: linear-gradient(45deg, #28a745, #20c997);
color: white;
}
.btn-yes:hover {
background: linear-gradient(45deg, #218838, #1ea080);
transform: translateY(-2px);
}
.btn-no {
background: linear-gradient(45deg, #dc3545, #fd7e14);
color: white;
}
.btn-no:hover {
background: linear-gradient(45deg, #c82333, #e8630a);
transform: translateY(-2px);
}
.btn-primary {
background: linear-gradient(45deg, #007bff, #6610f2);
color: white;
}
.btn-primary:hover {
background: linear-gradient(45deg, #0056b3, #520dc2);
transform: translateY(-2px);
}
.result {
background: linear-gradient(45deg, #28a745, #20c997);
color: white;
padding: 30px;
border-radius: 15px;
margin-top: 30px;
font-size: 1.5em;
}
.result h2 {
margin-bottom: 15px;
font-size: 2em;
}
.progress {
background: #e9ecef;
border-radius: 10px;
height: 10px;
margin: 20px 0;
overflow: hidden;
}
.progress-bar {
background: linear-gradient(45deg, #28a745, #20c997);
height: 100%;
width: 0%;
transition: width 0.5s ease;
}
@media (max-width: 600px) {
.container {
padding: 20px;
}
h1 {
font-size: 2em;
}
.numbers-grid {
grid-template-columns: repeat(auto-fit, minmax(40px, 1fr));
gap: 5px;
}
.buttons {
flex-direction: column;
align-items: center;
}
}
</style>
</head>
<body>
<div class="container">
<h1>🎯 Number Guessing Game</h1>
<div id="welcome" class="game-section active">
<div class="instructions">
<h3>How to Play:</h3>
<p>Think of a number between <strong>1 and 100</strong>.</p>
<p>I'll show you 7 groups of numbers. For each group, tell me if your number is included.</p>
<p>After all 7 groups, I'll magically tell you your number! 🎩✨</p>
</div>
<div style="margin: 20px 0;">
<label style="display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1.1em; color: #555;">
<input type="checkbox" id="randomizeToggle" style="transform: scale(1.2);">
Randomize numbers within groups
</label>
</div>
<button class="btn btn-primary" onclick="startGame()">Start Game</button>
</div>
<div id="game" class="game-section">
<div class="progress">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="group-container">
<div class="group-title" id="groupTitle"></div>
<p><strong>Is your number in this group?</strong></p>
<div class="numbers-grid" id="numbersGrid"></div>
<div class="buttons">
<button class="btn btn-yes" onclick="answerQuestion(true)">✅ Yes</button>
<button class="btn btn-no" onclick="answerQuestion(false)">❌ No</button>
</div>
</div>
</div>
</div>
<script>
let currentGroup = 0;
let groups = [];
function generateNumberGroups(maxNumber = 100, shouldRandomize = false) {
const generatedGroups = [];
let bitPosition = 0;
while ((1 << bitPosition) <= maxNumber) {
const group = [];
for (let num = 1; num <= maxNumber; num++) {
if (num & (1 << bitPosition)) {
group.push(num);
}
}
generatedGroups.push(group);
bitPosition++;
}
// Shuffle the groups to make it more mysterious
for (let i = generatedGroups.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[generatedGroups[i], generatedGroups[j]] = [generatedGroups[j], generatedGroups[i]];
}
if (shouldRandomize) {
// Shuffle numbers within each group but keep first number in place
generatedGroups.forEach(group => {
if (group.length > 1) {
const firstNumber = group[0];
const remainingNumbers = group.slice(1);
// Shuffle the remaining numbers
for (let i = remainingNumbers.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[remainingNumbers[i], remainingNumbers[j]] = [remainingNumbers[j], remainingNumbers[i]];
}
// Reconstruct the group with first number in place
group.splice(1, group.length - 1, ...remainingNumbers);
}
});
}
return generatedGroups;
}
function startGame() {
const shouldRandomize = document.getElementById('randomizeToggle').checked;
groups = generateNumberGroups(100, shouldRandomize);
currentGroup = 0;
result = 0;
document.getElementById('welcome').classList.remove('active');
document.getElementById('game').classList.add('active');
showCurrentGroup();
}
function showCurrentGroup() {
const groupTitle = document.getElementById('groupTitle');
const numbersGrid = document.getElementById('numbersGrid');
const progressBar = document.getElementById('progressBar');
groupTitle.textContent = "";
const progress = ((currentGroup) / groups.length) * 100;
progressBar.style.width = progress + '%';
numbersGrid.innerHTML = '';
groups[currentGroup].forEach(number => {
const numberDiv = document.createElement('div');
numberDiv.className = 'number-item';
numberDiv.textContent = number;
numbersGrid.appendChild(numberDiv);
});
}
function answerQuestion(answer) {
currentGroup++;
if (currentGroup < groups.length) {
showCurrentGroup();
} else {
endGame();
}
}
function endGame() {
const progressBar = document.getElementById('progressBar');
progressBar.style.width = '100%';
setTimeout(() => {
document.getElementById('game').classList.remove('active');
document.getElementById('welcome').classList.add('active');
}, 500);
}
</script>
</body>
</html>