Initial commit
This commit is contained in:
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
FROM nginx:alpine
|
||||||
|
|
||||||
|
COPY index.html /usr/share/nginx/html/
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
51
README.md
Normal file
51
README.md
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
# Number Guessing Game 🎯
|
||||||
|
|
||||||
|
A web-based number guessing game using binary representation magic!
|
||||||
|
|
||||||
|
## Quick Start with Docker
|
||||||
|
|
||||||
|
### Option 1: Using Docker Compose (Recommended)
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
### Option 2: Using Docker directly
|
||||||
|
```bash
|
||||||
|
# Build the image
|
||||||
|
docker build -t guess-number-game .
|
||||||
|
|
||||||
|
# Run the container
|
||||||
|
docker run -d -p 8080:80 --name guess-number-app guess-number-game
|
||||||
|
```
|
||||||
|
|
||||||
|
## Access the App
|
||||||
|
|
||||||
|
Open your browser and go to: http://localhost:8080
|
||||||
|
|
||||||
|
## How it Works
|
||||||
|
|
||||||
|
The game uses binary representation to guess numbers 1-100 in exactly 7 questions:
|
||||||
|
- Each group represents a power of 2 (1, 2, 4, 8, 16, 32, 64)
|
||||||
|
- When someone says "yes" to a group, add that group's value
|
||||||
|
- Sum all "yes" values to get their number
|
||||||
|
|
||||||
|
## Deployment Options
|
||||||
|
|
||||||
|
### Local Development
|
||||||
|
- Just open `index.html` in your browser
|
||||||
|
|
||||||
|
### Production Deployment
|
||||||
|
- **Docker**: Use the provided Docker setup
|
||||||
|
- **Static Hosting**: Deploy to Netlify, Vercel, or GitHub Pages
|
||||||
|
- **Web Server**: Serve with nginx, Apache, or any static file server
|
||||||
|
|
||||||
|
## Stopping the Docker Container
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# If using docker-compose
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
# If using docker run
|
||||||
|
docker stop guess-number-app
|
||||||
|
docker rm guess-number-app
|
||||||
|
```
|
50
demo.py
Normal file
50
demo.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
def generate_number_groups(max_number):
|
||||||
|
"""Generate groups of numbers based on binary representation."""
|
||||||
|
groups = []
|
||||||
|
bit_position = 0
|
||||||
|
|
||||||
|
while (1 << bit_position) <= max_number:
|
||||||
|
group = []
|
||||||
|
for num in range(1, max_number + 1):
|
||||||
|
if num & (1 << bit_position):
|
||||||
|
group.append(num)
|
||||||
|
groups.append(group)
|
||||||
|
bit_position += 1
|
||||||
|
|
||||||
|
return groups
|
||||||
|
|
||||||
|
def demo_guess(target_number):
|
||||||
|
"""Demo the guessing process with a known target number."""
|
||||||
|
print(f"🎯 Demo: Guessing the number {target_number}")
|
||||||
|
print("=" * 50)
|
||||||
|
|
||||||
|
max_number = 63
|
||||||
|
groups = generate_number_groups(max_number)
|
||||||
|
result = 0
|
||||||
|
|
||||||
|
for i, group in enumerate(groups):
|
||||||
|
print(f"\nGroup {i + 1} (bit position {i}):")
|
||||||
|
print("Numbers:", " ".join(map(str, group)))
|
||||||
|
|
||||||
|
is_in_group = target_number in group
|
||||||
|
print(f"Is {target_number} in this group? {'YES' if is_in_group else 'NO'}")
|
||||||
|
|
||||||
|
if is_in_group:
|
||||||
|
result += (1 << i)
|
||||||
|
print(f"Adding 2^{i} = {1 << i} to result")
|
||||||
|
|
||||||
|
print(f"Current result: {result}")
|
||||||
|
|
||||||
|
print(f"\n🎉 Final answer: {result}")
|
||||||
|
print(f"✅ Correct: {result == target_number}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Demo with a few different numbers
|
||||||
|
test_numbers = [7, 23, 42, 1, 63]
|
||||||
|
|
||||||
|
for num in test_numbers:
|
||||||
|
demo_guess(num)
|
||||||
|
print("\n" + "="*60 + "\n")
|
8
docker-compose.yml
Normal file
8
docker-compose.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
guess-number-app:
|
||||||
|
build: .
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
restart: unless-stopped
|
56
guess_number.py
Normal file
56
guess_number.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
def generate_number_groups(max_number):
|
||||||
|
"""Generate groups of numbers based on binary representation."""
|
||||||
|
groups = []
|
||||||
|
bit_position = 0
|
||||||
|
|
||||||
|
while (1 << bit_position) <= max_number:
|
||||||
|
group = []
|
||||||
|
for num in range(1, max_number + 1):
|
||||||
|
if num & (1 << bit_position):
|
||||||
|
group.append(num)
|
||||||
|
groups.append(group)
|
||||||
|
bit_position += 1
|
||||||
|
|
||||||
|
return groups
|
||||||
|
|
||||||
|
def guess_number():
|
||||||
|
print("🎯 Number Guessing Game")
|
||||||
|
print("Think of a number between 1 and 63")
|
||||||
|
print("I'll show you groups of numbers, tell me if your number is in each group")
|
||||||
|
print("-" * 50)
|
||||||
|
|
||||||
|
max_number = 63
|
||||||
|
groups = generate_number_groups(max_number)
|
||||||
|
result = 0
|
||||||
|
|
||||||
|
for i, group in enumerate(groups):
|
||||||
|
print(f"\nGroup {i + 1}:")
|
||||||
|
print("Numbers:", " ".join(map(str, group)))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
answer = input("Is your number in this group? (y/n): ").lower().strip()
|
||||||
|
if answer in ['y', 'yes', '1']:
|
||||||
|
result += (1 << i)
|
||||||
|
break
|
||||||
|
elif answer in ['n', 'no', '0']:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Please answer 'y' for yes or 'n' for no")
|
||||||
|
|
||||||
|
print(f"\n🎉 Your number is: {result}")
|
||||||
|
return result
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
guess_number()
|
||||||
|
|
||||||
|
play_again = input("\nDo you want to play again? (y/n): ").lower().strip()
|
||||||
|
if play_again not in ['y', 'yes', '1']:
|
||||||
|
print("Thanks for playing! 👋")
|
||||||
|
break
|
||||||
|
print()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
301
index.html
Normal file
301
index.html
Normal file
@ -0,0 +1,301 @@
|
|||||||
|
<!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>
|
||||||
|
<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) {
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return generatedGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startGame() {
|
||||||
|
groups = generateNumberGroups(100);
|
||||||
|
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>
|
Reference in New Issue
Block a user